JavaScript Flashcards

1
Q

What are JavaScript’s primitive data types?

A

Boolean, BigInt, Null, Number, String, Symbol, Undefined

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

What does the Number data type include?

A

All real numbers (positive and negative integers and floating point numbers, +/-Infinity)

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

What is a string?

A

Strings are a list of characters in a specific sequence surrounded by single or double quotes.

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

What is a Boolean?

A

Primitive data type which has the values of true or false.

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

What does a value of null represent?

A

Represents the intentional absence of a value.

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

The value of undefined represents…?

A

Represents the absence of a value and is used to convey the value does not exist.

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

What is an Object?

A

Collection of related data as key : value pairs.

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

Which values evaluate as falsy?

A

0, -0, 0n (BigInt zero) empty strings, null, undefined, NaN, false

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

What is an object property?

A

A property is a member of an object that associates a key with a value.

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

What is a method?

A

A method is a function which is associated with an object’s property.

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

What do comparison operators return?

A

A Boolean value of true/false

<, >, <=, >=, ==, ===, !=, !==
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Three ways to define a function in JavaScript:

A

Function declaration.
Function expression.
Arrow function (also known as arrow function expressions)

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

Key difference between a function declaration and function expression?

A

Function expressions are not hoisted and cannot be called before they appear in a program.

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

What is an anonymous function?

A

A function with no name property.

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

When would you use a do/while statement?

A

When you want the code block to execute at least 1 time.

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

Functions that always return a true or false value are referred to as…

A

Predicates

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

What is function composition?

A

Passing a function call as an argument to another function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
[].includes()
A

An array prototype method that determines if a value passed as an argument is an element of the calling array and returns true or false as appropriate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
[].slice()
A

An array prototype method which returns a portion of an array into a new array object selected from index start up to but not including index end. If no index end argument is given, the method will automatically slice to the final element of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
.splice()
A

Changes the contents of an array by removing or replacing existing elements and/or adding new elements. Returns an array of the deleted elements. Argument format is:

splice(startIndex, deleteCount, item1, item2, itemN)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
.push()
A

Adds one or more elements to the end of an array and returns the new length of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
.pop()
A

Removes the last element from the array and returns the removed element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
.join()
A

Creates and returns a new string by concatenating all of the elements in the array. If no separator argument is passed the elements will be comma separated with no spaces between elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
[].concat()
A

Merges two or more arrays and returns a new array.

[1, 2].concat([3])
\\ returns a new array [1, 2, 3]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
.shift()
A

Removes and returns the first element from an array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q
.unshift()
A

Adds one or more elements to the beginning of an array and returns the new length of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
.reverse()
A

Reverses the order of elements in an array and returns a reference to the same array. This method is destructive and mutates the original array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q
.flat()
A

Array prototype method that returns a new array with the sub-array elements concatenated into the new array, to the specified depth.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q
.sort()
A

Sorts the elements of an array in place and returns the reference to the same array, now sorted. The default sort behavior is to sort the array in ascending order, converting the array elements into strings, then comparing them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
.reduce()

What is it used for?
What is the structure of implementing the following Array method?
A

This array method is used to effectively reduce the contents of an array to a single value.

The reduce method takes two arguments:
1) a callback function with two parameters, the first parameter represents the accumulator value and the second parameter represents the current value of the iteration. The return value of the callback function is used as the accumulator in the next invocation of the callback.
2) initial value for the accumulator.

[].reduce((accumulator, element) => accumulator + element, \*initial value for accumulator variable*\)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q
Array.isArray()
A

Determines whether a passed value is an array and returns a Boolean value as appropriate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
Array.from()
A

Creates and returns a new array from an iterable. Can be passed a function expression that performs an action on each element of the iterable as a second argument to get behavior similar to .map()

Array.from('fox')
\\ returns [‘f’, ‘o’, ‘x’]
console.log(Array.from([1, 2, 3], x => x + x));
// Expected output: Array [2, 4, 6]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q
Object.keys()
A

Returns an array of an object’s own enumerable property names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q
{}.hasOwnProperty(’propertyString’)
A

Determines whether an object has the specified property as its own property (as opposed to inheriting it) and returns an appropriate Boolean value.

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

How can you iterate through all of an object’s properties?

A

Use a for/in loop

for (let prop in obj) {
// iterates through all object properties even those of an object's prototype
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q
Object.values()
A

Returns an array of an object’s own property values

Object.values({a : 1, b : 2}); // [1, 2]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q
Object.create()
A

Returns a new object that will inherit from an existing Object which is passed as the method argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q
Object.assign()
A

Copies all of a source object’s own properties into a target object and returns the modified target object.

const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
console.log(target);
// Expected output: Object { a: 1, b: 4, c: 5 }
console.log(returnedTarget === target);
// Expected output: true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q
Object.freeze()
A

Prevents an object from being changed and returns the same object that was passed as an argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q
Object.is()
A

returns a Boolean value indicating whether two arguments are the same value.

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

What do logical operators return?

A

logical operators return the last evaluated value.

|| &&
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q
.endsWith()
A

String prototype method which determines if the calling string ends with the characters in the specified string argument and returns an appropriate Boolean value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q
.charAt()

What if no passed argument? What if argument is out of bounds?
A

String prototype method that returns a new string with the character located at the index passed as an argument. If no passed argument, default of index 0 is used. If argument is out of bounds, returns an empty string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q
.substring()
A

String prototype method that returns part of the calling string from the start index up to but not including the end index, or to the end of the string if no end index supplied.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q
.split()
A

String prototype method which splits a string at a specified pattern and returns an array of substrings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q
''.includes()

How many arguments?
A

String prototype method which determines if a provided substring can be found in the calling string and returns an appropriate Boolean value. Takes an optional second argument that specifies which index in the string to start looking for the substring.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q
.match()
A

Retrieves the result of matching a string against a regular expression and returns and array whose contents depend on the presence or absence of the global flag.

const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';

const regex = /[A-Z]/g; //regex object

const found = paragraph.match(regex);
console.log(found);

// Expected output: Array ["T", "I"]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q
''.indexOf()
A

String prototype method that returns the index of the first occurrence of the provided substring.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q
.replace()
A

String prototype method that returns a new string with one, some, or all matches of an argument replaced by the replacement argument. The behavior of this method is flexible depending on the arguments passed. For instance you can pass a Regexp object for the matching pattern and a string as a replacement argument or even a function which is invoked for every match and its return value used as the replacement text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q
.padStart()
A

String prototype method returns a new string that is padded with another string as many times is needed to reach the desired length. The first argument is the length of string desired and the second argument is the string that will be used to pad the string to the desired length.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q
Math.random()
A

Generates a random number >= 0 and less than 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q
Math.floor()
A

Returns a rounded down integer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q
parseInt()
A

Parses a string and returns an integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q
parseFloat()
A

Parses a string and returns a floating point number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q
.toFixed()
A

Formats a number to the desired number of digits after the decimal point and returns a string representing the number. If no digit argument provided, method has a default value of zero digits.

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

What does it mean for a variable name to be idiomatic?

A

Variable names that are idiomatic are accurate, descriptive, understandable to the reader. Their name conveys an accurate meaning to the reader.

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

What would make a variable name illegal?

A

1) Cannot start with a digit
2) Cannot contain whitespace
3) Cannot contain any special characters
4) Cannot be identical to JavaScript’s reserved keywords

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

What are the three primary variable naming conventions?

A

1) camelCase - used for variable and function names
2) PascalCase - reserved for naming Constructor functions
3) SCREEMING_SNAKE_CASE - used for naming constants that represent unchanging configuration values in the program.

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

When do implicit type coercions occur?

A

When a non-strict operation of two of more values with differing data types occurs.

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

What happens when number values are compared with string values using the

==
(loose equality) operator?
A

Anytime a number and string are compared with

==
the string is coerced to a number.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

What happens when a Boolean value is compared to any other data type which performs a ‘loose’ comparison?

A

Boolean values are always coerced to numbers!

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

Anytime an object is compared to a primitive value the object is coerced to a … and then compared. How does the coercion behavior for empty array [] objects and empty objects {} differ?

A

Primitive. Empty array’s are coerced to the primitive value of zero whereas empty objects are coerced to a string value of ‘[object Object]’

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

Anytime one of the operands of the binary + operator is a string…

A

The other operand will be coerced to a string and the values will be concatenated.

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

Any combination of these data types used with the binary + operator will result in what behavior? (List the data types!)

A

Any combination of Booleans, Null, Number, Undefined will result in the values being coerced to numbers and added together.

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

What happens if one of the operands of the binary + operator is an object?

A

Both operands are coerced to strings and concatenated.

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

When using relational operators, when will JavaScript compare values lexicographically?

A

When both values are strings. Otherwise, JavaScript converts both operands to numbers before comparing them.

67
Q

You should not use the _____ or ____ explicit type coercions in template literals.

A

String() or .toString()

68
Q

What does a for/of loop do? What is the structure?

A

A for/of loop iterates over the elements of an array.

for (let value of array) { }
69
Q

What are variables? What do they store?

A

Variables are names for a specific area in memory. This memory location will either contain a primitive value or a pointer to something that cannot be easily stored in the default space allotted for each variable.

70
Q

What are valid variables in JavaScript?

A

Variables declared with let or var.
Constants declared with const.
Function names and parameters.
Class names.
Properties of the global object.

71
Q

What does the term ‘identifier’ refer to? What are appropriate to refer to as identifiers?

A

The term identifier is a broad term used to refer to variables, but also includes object property names.

72
Q

A variable’s scope determines…

A

Where the program can access that variable by name.

73
Q

What are some advantages to using a for loop?

A

Two main advantages.
1) Looping logic is all within the for ()statement and therefore easy to see at a glance.
2) For loops typically declare a variable for the looping logic, which is scoped to the for statement. An increment variable in a while loop is scoped outside the while statement. Using locally scoped variables can help to make code cleaner and better organized.

74
Q

What is break?

A

A JavaScript keyword that terminates the execution of the nearest loop.

75
Q

What is continue?

A

A JavaScript keyword that forces the JavaScript engine to skip to the next iteration of the loop.

76
Q

What is console.log()?

A

A method for writing information/data to the console.

77
Q

What is readline-sync? What is the .question method?

A

readline-sync is a simplified version of the readline node library that allows JavaScript programs to read input from the command line. The .question method allows for text to be displayed in the command line and for the user to provide input that the program can consume.

78
Q

What is require?

A

A node function used to import modules, JSON, and local files.

79
Q

What data type are functions? What are the implications of this?

A

Functions aren’t just code, they are objects! As such they can be passed to other functions, returned from functions, and assigned to variables and properties.

80
Q

What is the difference between say; and say(); ?

A

say; is a variable whose value is a reference to a function object. say(); is a function invocation which causes the JavaScript engine to temporarily ‘jump’ into the say function body and execute its code.

81
Q

When can you omit a return statement but still return a value?

A

This is possible within an arrow function if the body of the function contains only one expression that is not surrounded by curly braces.

82
Q

Function definition

A

is the entirety of a function. In the case of a function declaration the definition includes everything from the function keyword to the closing curly brace.

83
Q

Function invocation

A

A noun which describes the code written to invoke a function. Ex say() is a function invocation that enables the program to invoke the say function object when executed.

84
Q

What is an argument?

A

Primitive values or objects which are passed to a function.

85
Q

What is a parameter?

A

Declarations for the local variables used within a function to access its arguments.

86
Q

What are the two kinds of scope in JavaScript?

A

Global and Local scope

87
Q

Where are global variables accessible in a program?

A

Anywhere.

88
Q

What are the two forms of local scope?

A

block scope and function scope.

89
Q

Functions and blocks represent a sort of … scope. Whereas the global scope represents an … scope.

A

inner, outer

90
Q

Five function scope rules

A
  1. Variables declared in the outer scope are accessible in the inner scope.
  2. Variable declared in the inner scope are not accessible in the outer scope.
  3. Peer scopes do not conflict
  4. Inner scoped variables shadow outer scoped variables.
  5. Nested functions have their own scope.
91
Q

What is a block?

A

A related set of statements and expressions between a pair of opening and closing curly braces.

92
Q

How do you return values from a function?

A

With the return statement.

93
Q

What is output? Provide an example.

A

Output is how your computer or application presents the results to something other than itself. A common example of output is using console.log() to to display data to the console.

94
Q

What are return values?

A

Return values are results from functions or methods that are being presented to and used within the program.

95
Q

What does pass-by-value mean?

A

When a variable assigned to a primitive value is passed as an argument to a function, the function cannot reassign that variable.

96
Q

What does pass-by-reference mean?

A

When a variable that is assigned to an Object is passed as an argument to a function, the function can mutate the original object.

97
Q

What is a destructive function or method? Bonus: Is reassignment destructive?

A

Functions or methods that mutate their arguments. Bonus: reassignment is not destructive!

98
Q

Are return values from functions pass-by-value or pass-by-reference?

A

The same rules apply to function return values as do function arguments.

99
Q

Does variable assignment pass-by-value or pass by reference?

A

Trick question! The terms pass-by-value and pass-by-reference are only used to describe how values are passed to and returned from functions.

100
Q

What is the purpose of the call stack?

A

The call stack allows JavaScript to keep track of which function is executing and where execution should resume when the function returns.

101
Q

In relationship to the call stack, what is the main function? What other names does it go by?

A

The main function represents the global portion of the program and is also referred to as the stack frame.

102
Q

What happens to the call stack when a function returns?

A

When a function returns it is then ‘popped’ off the call stack and the program uses the next stack frame to determine where execution will resume from.

103
Q

What is an expression?

A

An expression is anything that JavaScript can evaluate to a value.

104
Q

What is a statement?

A

Code that demands a task.

105
Q

What is exception handling?

A

A process of managing errors in a predictable and reliable way.

106
Q

When are error objects created?

A

When the JavaScript interpreter cannot continue executing a program.

107
Q

When will JavaScript raise a ReferenceError?

A

Represents an error when a variable that doesn’t exist (or hasn’t yet been initialized) in the current scope is referenced.

108
Q

When will JavaScript raise a TypeError?

A

Represents an error when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type.

109
Q

When will JavaScript raise a SyntaxError? What is unique about these errors?

A

Represents an error when trying to interpret syntactically invalid code. SyntaxError is unique in that they typically occur at compilation time, not runtime.

110
Q

When will a catch block run? What happens after?

A

A catch block will run when, within a try/catch statement, the program raises an error (throws an exception). After the catch block runs, the program will resume running with the code that follows the entire try/catch statement.

111
Q

What is a guard clause? When should they be implemented?

A

A guard clause is code that guarantees data meets certain preconditions before it gets used. Guard clauses are best used when a function can’t trust that its arguments are valid.

112
Q

Some basic steps for detecting edge cases are…

A

Examine the assumptions inherent in your code. Can your program violate your assumptions? What happens when they are? These examples are your edge cases.

113
Q

Math.pow()

A

Returns the value of a base raised to a power.

114
Q

How can you get a random number between a specified minimum and maximum value?

A

(Math.random() * (maxVal - minVal)) + minVal
The resulting number can equal minVal but not maxVal (will always be bound to one less than the maxVal value).

115
Q

Variable scoping rules…

A

Describes how and where a language finds previously declared variables.

116
Q

Can you create variables without using a JavaScript declaration keyword? What happens if you do this?

A

Yes, but if done in code assume it’s an accident. Undeclared variables have global scope.

117
Q

What is short-circuit evaluation?

A

A mechanism which terminates the evaluation of an expression as soon as the minimum requirements for evaluating that expression has been met.

118
Q

What are JavaScript’s reference types?

A

Arrays, Objects, and Functions are all reference types (they are all objects)

119
Q

Are return values from functions pass-by-value or pass-by-reference?

A

The same rules apply to function return values as to function arguments. If the return value is a reference type it will be pass-by-reference, if the return value is a primitive it will be pass-by-value.

120
Q

Function side effects

A

Accesses a non-local variable and either reassigns it or mutates an Object referenced by the non-local variable.

Reads to or writes from an outside resource like the console, a database, files, or the browser.

Function throws an exception or calls a function which throws an exception.

121
Q
''.slice()
A

String prototype method which returns a substring from the calling String. Takes two arguments, the first argument is the start index and the second argument is the end index, not inclusive.

122
Q

What happens if you omit the second argument when using the string method

'string'.slice(2)
? What if no arguments are passed?
A

The method will return a substring with all characters from the start index to the end of the string. If no arguments are passed a copy of the calling string is returned.

123
Q

The String methods

String.prototype.slice()
and
String.prototype.substring()
are very similar. How do they differ? Which one should you use?
A

They differ in two ways:
1) When the start index is greater than the end index, substring will swap the arguments while slice will return an empty string.
2) When either argument is negative, substring treats them as 0 and returns a copy of the calling string, while, slice works from the end of the string.

124
Q

What is an array?

A

Arrays are lists of elements that are ordered by index, where each element can be any value.

125
Q

What happens here? Why?

let obj = { fruit: 'apple', vegetable: 'carrot', fruit: 'pear' }
A

obj is initialized to the Object { fruit: 'pear', vegetable: 'carrot' } Because object keys/properties must be unique, the first value associated with the fruit property is overwritten by the second fruit property value 'pear'.

126
Q

What happens if you attempt to access an out of bounds index on a String or Array with bracket notation?

A

Attempting to access either negative or positive out of bounds indices will return undefined.

127
Q

What happens if you use an invalid key when attempting to access a property of an object?

A

It will return undefined.

128
Q

What are the primary keys of an Array? What else is a valid key of an Array?

A

The Array’s index values. If the Array non-element properties, those properties are valid keys.

129
Q

Are ‘empty slots’ in an Array included in the Array’s length property? What about non-element properties to the array?

A

Empty slots are included in the length property, however non-element properties are not! Non-element properties are key/value pairs that do not use integer indexes.

130
Q

What will the following code snippets return?

'this is a string'.split();

'abcdef'.split('');

'apple,orange,mango'.split(',');
A

1) [‘this is a string’]
2) [‘a’,’b’,’c’,’d’,’e’,’f’]
3) [‘apple’, ‘orange’, ‘mango’]

131
Q

How can you convert an Object to an Array?

A
Object.entries(object)
will return an Array with the key/value pairs of the passed Object as nested arrays.
132
Q

What is logged to the console? What is the takeaway from the following code?

let string = 'bob';
string[0] = 'B';
console.log(string);
A

string element reassignment, even though it’s syntactically permitted, doesn’t affect the string.

133
Q

String.prototype.trim()

A

Returns a new string with whitespace removed from the beginning and end of the calling string.

134
Q

String.prototype.trimStart()

A

Returns a new string with whitespace removed from the beginning of the calling string.

135
Q

String.prototype.trimEnd()

A

Returns a new string with whitespace removed from the end of the calling string.

136
Q

What does ''.charAt() return when passed an out of bounds index?

A

'' an empty string.

137
Q
String.prototype.charCodeAt()

Bonus: what if you don’t pass an argument?
A

Returns the unicode code point or character code of the character at the index passed as an argument.
Bonus: the method returns the character code at index 0.

138
Q

What is a Unicode code point?

A

The number that represents a given character at the machine level.

139
Q
String.fromCharCode()
A

returns the character represented by the character code value.

140
Q
String.prototype.repeat()
A

returns a new string which contains the specified number of copies of the string on which it was called, concatenated together

141
Q

What is the following an example of?

let keyValue = [ 'key', 'value']

let [ key, value ] = keyValue

How many variables are in this snipppet? what are their values?
A

This is an example of array destructuring assignment. Array destructuring assignment allows us to assign elements of the array to multiple variables by wrapping the variable names in brackets. There are 3 variables.

key // 'key'

value // 'value'
142
Q
.forEach()
A

forEach is an iterative array method that executes a provided callback function once for every element in the calling array and always returns undefined. forEach will always invoke the callback function for every element in the calling array unless an error is thrown. The callback function takes up to three arguments: element, index, array. It’s typically used to execute side effects at the end of a method chain.

143
Q
.filter()
A

filter is an iterative array method that executes a provided callback function once for every element in the calling array and returns a new array containing the values for which the callback function returns a truthy value. The callback function can take up to three arguments: element, index, array.

144
Q
.map()
A

map is an iterative array method that returns a new array populated with the return values of the provided callback function and contains the same number of elements as the calling array. The callback function takes up to three arguments: element, index, array.

145
Q
.fill()
A

Array prototype method that mutates its caller by replacing elements in an array. The first argument is the replacement value, second argument is the start index, third argument is the up to but not including end index.

146
Q
.some()
A

Array prototype method that executes a callback function for every element in an array. If at least one return value from the callback is truthy, return boolean true. Otherwise return false.

147
Q
.every()
A

Array prototype method that executes a callback function for every element in an array. If every callback return value is truthy, return true. Otherwise return false.

148
Q
.find()
A

Return the first element from the calling array that returns truthy for the provided callback function. Returns undefined if no elements return truthy.

149
Q
.findIndex()
A

Returns the index of the 1st element that returns truthy from the provided callback function. Returns -1 if no truthy value returned from callback.

150
Q

How can you easily determine if the value NaN is in an array?

A

Use the .includes() array method.

151
Q

Fun fact: Most built-in array methods _________ non-element properties and ______.

A

ignore, empty slots

152
Q

Useful lexicographic ordering rules:

A
  • All uppercase letters come before lowercase letters
  • Digits (0-9) and most punctuation come before letters
  • Several punctuation characters between the uppercase and lowercase letters.
153
Q

.sort() can take an optional callback function with two parameters a, b, which represent elements from the calling array being compared. The return values of the callback dictate how the elements are sorted. What are these rules?
Bonus: Expression for ordering in ascending order? Descending order?

A

return value > 0 b before a
return value < 0 a before b
return value === 0 no change

154
Q

Modern way for creating a shallow copy of an array?

A

Spread syntax.

155
Q

What is a shallow copy?

A

A shallow copy contains a shared reference to the original variable. Changes on shallow copies are reflected on origin object.

156
Q

How can you create a deep copy? What’s the catch?

A

Deep copies can be created by serializing an object to text using let serializedObj = JSON.stringify(obj) and then using JSON.parse(serializedObj) to create a new object. The catch is this method will only work on simple objects and nested arrays.

157
Q

If you attempt to _______ a frozen object it will fail _____. If you attempt to use a ______ method on a frozen object it will _______.

A

reassign, fail silently
mutating, throw a TypeError

158
Q

Determine if an object has been frozen…

A

Object.isFrozen(obj)

159
Q
Object.fromEntries()
A

Object static method which transforms an array of nested array key/value pairs into an object. The input array should be formatted the same as the

Object.entries()
return value.
160
Q

What does it mean that arrays in JavaScript are sparse?

A

The number of elements in an array isn’t necessarily the same as its length: there can be gaps in the array (empty slots).

161
Q

What is a higher-order function?

A

A function which accepts functions as parameters and/or returns a function.

162
Q

Why would a for/in loop and Object.keys() produce different results for iterating over Object properties?

A

A for/in loop iterates over an object’s prototype properties as well as the object’s own properties. The Object.keys() static method returns an array of an objects own properties.

163
Q

How are sparse arrays created?

A

1) Increase the size of the length property of the array without adding any values to it.

164
Q

How does Array.prototype.sort() handle undefined values in an array?

A

They are always placed at the end of the array no matter what the other values are.