Javascript Flashcards

(92 cards)

1
Q

array.forEach

A

Executes a provided function once for each array element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

array.map

A

Creates a new array with the results of calling a provided function on every element in the calling array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

array.filter

A

Creates a new array with all elements that pass the test implemented by the provided function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

array.find

A

Returns the first element in the array that satisfies the provided testing function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

array.findIndex

A

Returns the index of the first element in the array that satisfies the provided testing function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

array.some

A

Checks if at least one element in the array passes the test implemented by the provided function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

array.every

A

Checks if all elements in the array pass the test implemented by the provided function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

array.reduce

A

Executes a reducer function on each element of the array, resulting in a single output value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

array.reduceRight

A

Same as reduce, but processes the array from right to left.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

array.sort

A

Sorts the elements of an array in place and returns the sorted array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

array.slice

A

Returns a shallow copy of a portion of an array into a new array object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

array.splice

A

Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

array.concat

A

Returns a new array comprised of this array joined with other array(s) and/or value(s).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

array.includes

A

Determines whether an array includes a certain element, returning true or false as appropriate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

array.indexOf

A

Returns the first index at which a given element can be found in the array, or -1 if it is not present.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

array.lastIndexOf

A

Returns the last index at which a given element can be found in the array, or -1 if it is not present.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

array.join

A

joins all elements of an array into a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

isArray

A

Determines whether the passed value is an Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

array.toString

A

Returns a string representing the specified array and its elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

array.reverse

A

Reverses the elements of an array in place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Primitive Data Types

A

Stored directly in the variable’s location: Primitive data types are stored directly in the variable’s memory location.

Immutable: Once a primitive value is assigned to a variable, its value cannot be changed. Any operation that appears to modify a primitive value actually creates a new value.

Examples: Number, String, Boolean, Undefined, Null, Symbol (ES6).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Non-Primitive Data Types (Reference Types):

A

Stored by reference: Non-primitive data types are stored by reference, meaning that the variable contains a reference (memory address) to the actual value stored elsewhere in memory.

Mutable: Non-primitive values can be modified because they are stored by reference. Changing the value through one reference affects all other references to that value.

Examples: Object, Array, Function, Date, RegExp.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Undefined

A

undefined is a primitive value that represents a variable or object property that has not been assigned a value.

It indicates that a variable has been declared but has not yet been initialized or assigned any value.

It is automatically assigned to variables that have been declared but not explicitly initialized.

Use undefined when a variable or object property has not been assigned any value, either because it has not been initialized or because it has been explicitly set to undefined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

null

A

null is a primitive value that represents the intentional absence of any object value.

It is often used to explicitly indicate that a variable or object does not have a value.

null is explicitly assigned by developers to signify that a variable or object property should not reference any object.

Use null when you want to explicitly denote the intentional absence of a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Symbol
It represents a unique and immutable value that can be used as an identifier for object properties. Symbols are created using the Symbol() function. Symbols are primarily used as unique property keys for objects. They help avoid property name collisions in objects, especially when working with third-party code or libraries.
25
Object.keys(object)
Returns an array of a given object's own enumerable property names.
26
Object.values(object)
Returns an array of a given object's own enumerable property values.
27
Object.entries(object)
Returns an array of a given object's own enumerable string-keyed property [key, value] pairs.
28
Object.assign(target, source1, source2, ...)
Copies the values of all enumerable own properties from one or more source objects to a target object. It returns the modified target object.
29
Object.freeze(object)
Freezes an object, preventing new properties from being added to it and existing properties from being removed or changed. It also prevents the values of existing properties from being changed.
30
Object.seal(object)
Seals an object, preventing new properties from being added to it. However, existing properties can still be changed.
31
Object.getOwnPropertyNames(object)
Returns an array of all property names (including non-enumerable properties) of a given object.
32
new Date()
Creates a new Date object representing the current date and time.
33
Date.now()
Returns the numeric value corresponding to the current time—the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC (the Unix epoch).
34
getFullYear()
Returns the year (four digits for dates between year 1000 and 9999) of the specified date according to local time.
35
getMonth()
Returns the month (0-11) of the specified date according to local time.
36
getDate()
Returns the day of the month (1-31) for the specified date according to local time
37
getDay()
Returns the day of the week (0-6) for the specified date according to local time. (0 for Sunday, 1 for Monday, and so on.)
38
getHours()
Returns the hour (0-23) in the specified date according to local time.
39
getMinutes()
Returns the minutes (0-59) in the specified date according to local time.
40
getSeconds()
Returns the seconds (0-59) in the specified date according to local time.
41
getMilliseconds()
Returns the milliseconds (0-999) in the specified date according to local time.
42
Object.keys() with filter()
You can use Object.keys() to get an array of keys from the object and then filter this array based on certain conditions
43
Object.entries() with filter()
You can use Object.entries() to get an array of key-value pairs (as arrays) and then filter this array based on certain conditions
44
Reduce() method on Object
You can use the reduce() method to filter the object and accumulate the result.
45
Using for...in loop for Object
You can iterate over the object using a for...in loop and filter based on certain conditions
46
Using Object.entries() with map()
Object.entries() method returns an array of a given object's own enumerable property [key, value] pairs.
47
Using Object.keys() with map()
Object.keys() method returns an array of a given object's own enumerable property names.
48
What is strict mode
Makes debugging easier: Strict mode makes debugging easier by throwing more exceptions for common coding errors, such as using undeclared variables. Prevents accidental global variables: In non-strict mode, assigning a value to an undeclared variable creates a global variable. In strict mode, assigning to an undeclared variable throws a ReferenceError. Makes eval() safer: In strict mode, variables and functions declared inside eval() are not created in the surrounding scope, avoiding potential naming conflicts. Disallows duplicate property names in objects: In strict mode, defining a property multiple times in an object literal or using duplicate parameter names in a function declaration causes a syntax error. Disallows octal literals: In strict mode, octal literals (e.g., 012) are not allowed, preventing potential confusion with decimal numbers. Prevents with statement: The with statement is disallowed in strict mode, as it can lead to ambiguous code and performance issues
49
var
* Function Scope: Variables declared with var are function-scoped. They are accessible anywhere within the function in which they are declared. * Hoisting: Variables declared with var are hoisted to the top of their scope. This means you can access the variable before it's declared without getting an error, but its value will be undefined. * Reassignable: Variables declared with var can be reassigned and re-declared within the same scope.
50
let
* Block Scope: Variables declared with let are block-scoped. They are accessible only within the block in which they are declared (block is defined by {}). * No Hoisting: Variables declared with let are not hoisted to the top of their scope. Trying to access the variable before it's declared will result in a ReferenceError. * Reassignable: Variables declared with let can be reassigned, but not re-declared within the same scope.
51
const
* Block Scope: Like let, variables declared with const are block-scoped. * No Hoisting: Variables declared with const are not hoisted to the top of their scope. * Immutable: Variables declared with const cannot be reassigned. However, if the variable is an object or array, its properties or elements can be modified.
52
Using ==
Using loose equality (==)
53
===
strict equality (===)
54
Not using hasOwnProperty()
When iterating over object properties, not using hasOwnProperty() can cause unexpected behavior if the object's prototype chain has been modified.
55
str.charAt(index)
Returns the character at the specified index in a string.
56
str.charCodeAt(index)
Returns the Unicode value of the character at the specified index in a string.
57
str.concat(str1, str2, ..., strN)
Combines two or more strings together. javascript
58
str.includes(searchString, position)
Checks if a string contains another specified string
59
str.indexOf(searchValue, fromIndex)
Returns the index of the first occurrence of a specified value in a string.
60
str.lastIndexOf(searchValue, fromIndex)
Returns the index of the last occurrence of a specified value in a string.
61
str.slice(startIndex, endIndex)
Extracts a section of a string and returns it as a new string.
62
str.split(separator, limit)
Splits a string into an array of substrings based on a specified separator.
63
str.substring(startIndex, endIndex)
Returns the part of the string between the start and end indexes.
64
str.toLowerCase()
Converts a string to lowercase.
65
str.toUpperCase()
Converts a string to uppercase.
66
str.trim()
Removes whitespace from both ends of a string.
67
Callbacks
Traditionally, JavaScript used callbacks to handle asynchronous operations. Callbacks are functions passed as arguments to other functions, which are then executed when the asynchronous task completes. However, this approach can lead to callback hell, making code difficult to read and maintain, especially when dealing with nested callbacks.
68
Promises
Promises provide a cleaner way to work with asynchronous code by representing a value (or the eventual completion or failure of an asynchronous operation) that may be available now, in the future, or never. A Promise can be in one of three states: pending, fulfilled (resolved), or rejected. Promises have then() and catch() methods to handle successful and failed outcomes, respectively.
69
Async/Await
Async functions and the await keyword provide a more concise and readable way to write asynchronous code. Async functions are declared with the async keyword, and they always return a Promise. Within an async function, the await keyword can be used to pause the execution of the function until a Promise is settled (resolved or rejected). This makes asynchronous code look more synchronous and easier to understand.
70
Error Handling
Both Promises and async/await support error handling using catch() blocks or try-catch blocks, respectively. This allows you to gracefully handle errors that occur during asynchronous operations.
71
Chaining
Promises and async/await can be chained together to handle multiple asynchronous operations sequentially or in parallel, depending on the requirements of your code.
72
Single Thread
JavaScript is single-threaded, meaning it can only execute one piece of code at a time. This is different from multi-threaded environments where multiple threads of execution can happen concurrently.
73
Non-blocking I/O
JavaScript uses non-blocking I/O operations, which means that it doesn't wait for I/O operations like network requests or file system operations to complete before moving on to the next task. Instead, it delegates these tasks to the browser or runtime environment and continues executing other code.
74
Event Queue
When an asynchronous operation completes or an event occurs (like a user clicking a button), the callback associated with that operation or event is placed into a queue called the event queue.
75
Event Loop
The event loop continuously checks the call stack (the place where function calls are managed) and the event queue. If the call stack is empty, it takes the first callback from the event queue and pushes it onto the call stack, allowing it to execute. This process continues indefinitely, ensuring that asynchronous operations are handled in the order they were received and that the JavaScript engine remains responsive.
76
Closures
They occur when a function retains access to its lexical scope even after the outer function has finished executing. This means that inner functions have access to the variables and parameters of their outer functions, even after the outer function has returned.
77
Prototype
Every JavaScript object has a prototype. When you create an object using object literals {}, arrays [], or functions, they inherit properties and methods from a prototype. You can access an object's prototype using Object.getPrototypeOf() or the __proto__ property.
78
Prototype Chain
JavaScript objects form a chain of prototypes, known as the prototype chain. When you access a property or method on an object, JavaScript looks for it in the object itself. If it's not found, it looks up the prototype chain until it finds the property or until it reaches the end of the chain (the Object.prototype).
79
Prototypal Inheritance:
Objects inherit properties and methods from their prototype. If a property or method is not found on the object itself, JavaScript automatically looks for it in the object's prototype and continues up the prototype chain until it finds it. This is known as prototypal inheritance.
80
Constructor Functions
Constructor functions can be used to create objects with shared properties and methods. When you use the new keyword with a constructor function, it creates a new object that inherits from the constructor's prototype.
81
Object.prototype
At the top of the prototype chain is Object.prototype, which contains common methods and properties shared by all objects in JavaScript, such as toString(), hasOwnProperty(), etc.
82
Event Emitters
Event emitters are objects in Node.js that allow you to register listeners for named events and emit events when certain actions occur. They are commonly used for handling asynchronous operations, such as I/O operations, network requests, or user interactions.
83
Observables
Observables are a pattern used in reactive programming to handle data streams and asynchronous events. They represent a sequence of values over time and provide operators to manipulate and process those values. Observables are commonly used in libraries like RxJS.
84
When to use Array of objects?
Use an array of objects when you need to maintain an ordered collection of elements, and each element is a distinct entity with multiple properties. Arrays allow duplicate elements, so if your data can contain duplicates, an array might be more appropriate. Arrays provide convenient methods for accessing, adding, removing, and manipulating elements, such as push, pop, splice, etc. If you need to perform operations that rely on the index or specific order of elements, an array is usually the better choice.
85
When to use a set?
Use a Set when you need a collection of unique elements and duplicates are not allowed or not desirable. Sets automatically handle duplicate values by only storing unique elements. If you want to ensure that each element appears only once in your collection, a Set is a good choice. Sets provide methods for adding, removing, and checking for the presence of elements, such as add, delete, has, etc. Sets are especially useful when you need to perform set operations like union, intersection, or difference between collections.
86
create set
const mySet = new Set();
87
add to set
mySet.add(1); availableBooks.set('one', { title: 'One', author: 'Author One', available: true });
88
access entries in set
availableBooks.get('one') // Output: { title: 'One', author: 'Author One', available: true }
89
Checking for existence in set
availableBooks.has('two') // Output: true
90
Removing an entry set
availableBooks.delete('three');
91
Iterating over entries in set
availableBooks.forEach((value, key) => { console.log(`${key}: ${value.title} by ${value.author}`); });