JavaScript Flashcards

1
Q

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

Strings are combined using the addition operator

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

What purpose(s) does the + plus operator serve in JavaScript?

A

It either adds numbers together or concatenates strings

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

What data type is returned by comparing two values (, ===, etc)?

A

boolean

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

What does the += “plus-equals” operator do?

A

Takes the variable and either adds a number or concatenates a string to itself

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

What are objects used for?

A

They are used to store a group of variables

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

What are object properties?

A

The individual variables stored in an object

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

Describe object literal notation.

A

Declare a variable, use opening curly brace, then list each property (name: value,) then close with a curly brace

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

How do you remove a property from an object?

A

Use the delete keyword (delete object.propertyname)

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

What are the two ways to get or update the value of a property?

A

dot notation (object.newproperty) or bracket notation (object[‘newproperty’]) - dot notation is preferred

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

How are arrays different from “plain” objects?

A
  • Arrays have order.
  • Arrays have methods to remove items and the array will adapt/update for any changes made
  • They are simply listed, they don’t have an additional value or label assigned to them and they operate differently
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

Tells you how many items there are in an array

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

How do you calculate the last index of an array?

A

Length - 1

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

Describe the parts of a function definition.

A

Function keyword, function name (optional), parameters separated by commas and surrounded by parentheses, code block, return statement (optional)

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

Describe the parts of a function call

A

Function name, arguments

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

The function definition has parameters and a code block which set everything up, whereas the call simply plugs arguments into the parameters

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

What is the difference between a parameter and an argument?

A

Parameter is a placeholder, whereas an argument is what’s plugged into that placeholder

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

Why are function parameters useful?

A
  • Allows for more concise code, since they only have to be written once
  • Allows for different results for each function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What two effects does a return statement have on the behavior of a function?

A
  • Ends the function

- Returns the value of the function

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

Why do we log things to the console?

A

To check that everything is working properly and to keep track of output

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

What is a method?

A

A method is a function that is a property of an object

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

How is a method different from any other function?

A
  • Attached to an object, whereas functions a free-floating

- Can access data within objects

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

How do you remove the last element from an array?

A

Pop method

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

How do you round a number down to the nearest integer?

A

Math.floor method

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

How do you generate a random number?

A

Math.random method

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

How do you delete an element from an array?

A

Splice method

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

How do you append an element to an array?

A

Push method

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

How do you break a string up into an array?

A

Use the split method

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

Do string methods change the original string? How would you check if you weren’t sure?

A

Yes. You would log the string to the console or go to MDN

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

Is the return value of a function or method useful in every situation?

A

no

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

Give 6 examples of comparison operators.

A

==, ===, !=, >,

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

What is the purpose of an if statement?

A

Allows functions to execute different types of code depending on if a condition is met; makes a decision

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

Is else required in order to use an if statement?

A

No, but not including it could result in undefined variables

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

Describe the syntax (structure) of an if statement.

A

If keyword, condition, code block

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

What are the three logical operators?

A

&& (and), || (or), ! (not)

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

How do you compare two different expressions in the same condition?

A

Use the ‘and’ or the ‘or’ logical operators

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

What data type do comparison expressions evaluate to?

A

numbers

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

What is the purpose of a loop?

A

Allows code to be run multiple times automatically

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

What is the purpose of a condition expression in a loop?

A

Determines how many times the code is executed and when it stops

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

What does “iteration” mean in the context of loops?

A

Each time the code is run and the loop is repeated

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

When does the condition expression of a while loop get evaluated?

A

Before each iteration (is checked to see if code meets the condition)

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

When does the initialization expression of a for loop get evaluated?

A

The first time the loop is run

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

When does the condition expression of a for loop get evaluated?

A

Every time the loop is run, before the iteration

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

When does the final expression of a for loop get evaluated?

A

Every time the loop is run and still meets the condition expression

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

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

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

What does the ++ increment operator do?

A

Increases value by one and assigns it to the same variable

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

How do you iterate through the keys of an object?

A

Use a for in loop

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

Which “document” is being referred to in the phrase Document Object Model?

A

The HTML document

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

What is the word “object” referring to in the phrase Document Object Model?

A

The javascript object datatype

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

What is a DOM Tree?

A

A representation of all the objects within an HTML document and how they are related

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

Give two examples of document methods that retrieve a single element from the DOM.

A

getElementByID(), querySelector()

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

getElementsByClassName, querySelectorAll()

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

Why might you want to assign the return value of a DOM query to a variable?

A

To make it easier to access and to prevent the computer from having to search thru entire html doc every time

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

What console method allows you to inspect the properties of a DOM element object?

A

Console.dir

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

Why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

It needs to be run at the end when every HTML object has been established

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

What does document.querySelector() take as its argument and what does it return?

A

Argument: css selector, returns: the first matching element

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

What does document.querySelectorAll() take as its argument and what does it return?

A

Argument: CSS selector, returns: a node list of every element that matches that selector

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

What is the purpose of events and event handling?

A

Allow for interactivity and for code to be triggered when an event happens

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

What do [] square brackets mean in function and method syntax documentation?

A

Used to implement optional object

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

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener

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

What is a callback function?

A

A function passed into another function as an argument, which is then invoked inside the outer function to complete an action

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

What object is passed into an event listener callback when the event fires?

A

Huge object which contains all of the info of an event

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

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

The section of html code that the event is targeting. You could log the event target to the console or select it with the query selector. Go to MDN.

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

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

The second snippet runs the function first, whereas the first snippet runs it after the event

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

What is the className property of element objects?

A

holds the name of an element’s class attribute

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

How do you update the CSS class attribute of an element using JavaScript?

A

You use the className method

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

What is the textContent property of element objects?

A

Holds the text content of an element

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

How do you update the text within an element using JavaScript?

A

Use the text content method

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

Is the event parameter of an event listener callback always useful?

A

No because you don’t always need info about the event (i.e. as seen in the exercise)

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

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

Vastly more complicated

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

Why is storing information about a program in variables better than only storing it in the DOM?

A

Easier to access for both the programmer and the computer

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

What event is fired when a user places their cursor in a form control?

A

focus

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

What event is fired when a user’s cursor leaves a form control?

A

blur

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

What event is fired as a user changes the value of a form control?

A

input

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

What event is fired when a user clicks the “submit” button within a ?

A

submit

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

What does the event.preventDefault() method do?

A

Prevents an event’s default action from happening

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

What does submitting a form without event.preventDefault() do?

A

Refreshes the page and adds the input data onto the URL

79
Q

What property of a form element object contains all of the form’s controls.

A

form

80
Q

What property of form a control object gets and sets its value?

A

Value

81
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

You won’t know which part of the code doesn’t work, causing you to take much more time to find out where things are going wrong

82
Q

What is an advantage of having your console open when writing a JavaScript program?

A

Can easily see when an error occurs

83
Q

Does the document.createElement() method insert a new element into the page?

A

no

84
Q

How do you add an element as a child to another element?

A

appendChild method

85
Q

What do you pass as the arguments to the element.setAttribute() method?

A

attibute type and attribute value

86
Q

What steps do you need to take in order to insert a new element into the page?

A

CreateElement method and assign it to a var, find where you want to append it, and appendchild

87
Q

What is the textContent property of an element object for?

A

Gets or sets the text content for that element

88
Q

Name two ways to set the class attribute of a DOM element.

A

Set attribute, and classname

89
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A
  • Don’t have to write as much html
  • You can make a single function that creates a complex chunk of code to be used more than once
  • Can customize html content thru javascript
90
Q

What is the event.target?

A

The target of the event or the element being interacted with

91
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

The default document flow is event bubbling which starts at the most specific elements

92
Q

What DOM element property tells you what type of element it is?

A

Tag name property

93
Q

What does the element.closest() method take as its argument and what does it return?

A

Takes a selector as an argument and returns the closest parent element that matches that selector

94
Q

How can you remove an element from the DOM?

A

Use the remove method

95
Q

If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

Just assign the event listener to a parent element using the callback function and have the call back function target button elements
o (event delegation)

96
Q

What is the event.target?

A

The target of the event or the element being interacted with

97
Q

What does the element.matches() method take as an argument and what does it return?

A

A string selector, returns Boolean value

98
Q

How can you retrieve the value of an element’s attribute?

A

getAttribute() method

99
Q

At what steps of the solution would it be helpful to log things to the console?

A

Logging either node list at the end of the click function to make sure the element classes were changed

100
Q

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

You would have to put an event listener on every tab

101
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

You would have to write three individual if statements checking to see if the event target matches the nodelist elements

102
Q

What is JSON?

A

a text-based data format following JavaScript object syntax that exists as a string

103
Q

What are serialization and deserialization?

A
  • Serialization: the process of converting an object into a stream of bytes so that it can be transferred or stored
  • Deserialization: converting that stream of bytes into object
104
Q

Why are serialization and deserialization useful?

A

Allow data to be stored or transfered

105
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

Json.stringify() (stringify method of the json property)

106
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

Use json.parse method

107
Q

How to you store data in localStorage?

A

Localstorage.setitem

108
Q

How to you retrieve data from localStorage?

A

Localstorage.getitem

109
Q

What data type can localStorage save in the browser?

A

only strings

110
Q

When does the ‘beforeunload’ event fire on the window object?

A

When the window, document, and its resources are about to be unloaded

111
Q

What is a method?

A

A function which is a property of an object

112
Q

How can you tell the difference between a method definition and a method call?

A

A method call looks like a property and is written in dot notation, whereas defining a method takes place within the object itself and looks similar to a function definition

113
Q

Describe method definition syntax (structure).

A

The object variable is defined, then within that object the method’s property name is defined with the value of a function definition

114
Q

Describe method call syntax (structure).

A

The object name followed by a dot and the name of the method with parentheses

115
Q

How is a method different from any other function?

A

It’s specific to an object, whereas functions are defined and called outside of an object

116
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (as properties) and behavior (as methods)

117
Q

What are the four “principles” of Object-Oriented Programming?

A

o Abstraction
o Encapsulation
o Inheritance
o Polymorphism

118
Q

• What is this in JavaScript?

A

An implicit parameter of javascript functions that’s determined at the call of a function and that is recognized as either the object involved when the function is called or the global window object

119
Q

What does it mean to say that this is an “implicit parameter”?

A

Its available in a function’s code block even though it was never declared as a variable or included as a property (automatically included)

120
Q

When is the value of this determined in a function; call time or definition time?

A

Call time

121
Q

How can you tell what the value of this will be for a particular function or method definition?

A

You can’t

122
Q

How can you tell what the value of this is for a particular function or method call?

A

It updates to whatever the object is that the method is being called from and if that isn’t there, this defaults to the window value

123
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal inheritance

124
Q

What is a prototype in JavaScript?

A

An object that contains a collection of properties and methods which other objects can access to perform certain tasks

125
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?

A

They exist within the inherited prototype object

126
Q

If an object does not have its own property or method by a given key, where does JavaScript look for it?

A

The object’s prototype object

127
Q

What does the new operator do?

A

The new operator lets developers create an instance of a user-defined object type

128
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

The prototype property

129
Q

What does the instanceof operator do?

A

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

130
Q

What is a “callback” function?

A

a function passed into another function as an argument

131
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout function

132
Q

How can you set up a function to be called repeatedly without using a loop?

A

Use the setInterval function

133
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0, meaning the task is executed immediately

134
Q

What do setTimeout() and setInterval() return?

A

They both return a positive integer value which identifies the timer created by the call

135
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

get

136
Q

What three things are on the start-line of an HTTP request message?

A

Method, request target, and version

137
Q

What three things are on the start-line of an HTTP response message?

A

Protocol version, status code, and status text

138
Q

What are HTTP headers?

A

A string followed by a colon and a value, whose structure depends on the header all of this is on a single line

139
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

MDN

140
Q

Is a body required for a valid HTTP request or response message?

A

No

141
Q

What is AJAX?

A

A technique for loading data into part of a page without having to refresh the page

142
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

143
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

144
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

Load event

145
Q

Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

They both use the same prototype object

146
Q

What is a code block? What are some examples of a code block?

A

A section of code contained within a set of curly braces.

Code blocks are used in conditionals, loops, or functions.

147
Q

What does block scope mean?

A

Block scope refers to declarations within a code block.

If you define something within the scope of a code block, it isn’t recognized globally

148
Q

What is the scope of a variable declared with const or let?

A

Let: block-scoped
Const: block-scoped

149
Q

What is the difference between let and const?

A

Const values cannot be reassigned, whereas let values can

150
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

Because you are creating a new array, not changing what the const is assigned to

151
Q

How should you decide on which type of declaration to use?

A

Use let if you want a more dynamic variable and use const if you want that variable to remain the same

152
Q

What is the syntax for writing a template literal?

A

Use the back tick ( ` ) instead of quotes

Using string interpolation instead of concatenation

153
Q

What is “string interpolation”?

A

Implementing variables and expressions into a template literal using the $ and {}

154
Q

What is destructuring, conceptually?

A

Taking the individual object properties or array items and assigning them to a variable

155
Q

What is the syntax for Object destructuring?

A

Type of declaration (let, const), followed by curly braces, followed by property name, colon, new variable name (or just the property if you want the variable to share the same name), followed by an equal sign and the name of the variable the object is assigned to

const { property } = object

156
Q

What is the syntax for Array destructuring?

A

Variable declaration keyword, followed by square brackets including names of new variables at the indexes of the original array separated by commas, followed by an equal sign and the name of the original array

const [item1, item2] = array

157
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

For objects, the Name of the object is at the end, and the Key/value pairs are actually key/variable pairs, meaning the right side of each property won’t be a string or number.
For arrays, similar syntax, except each item is the name of the new variable.

158
Q

What is the syntax for defining an arrow function?

A

pair of parentheses either blank or with parameters followed by equal sign and greater than sign followed by code block

159
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

You can’t run multiple lines of code

You don’t need a return statement

160
Q

How is the value of this determined within an arrow function?

A

Arrow functions determine this at definition time as opposed to call time with normal functions.
Use arrow functions as inline callbacks

161
Q

What is the process object in a Node.js program?

A

a global object that provides information about and control over, the current Node.js process

162
Q

How do you access the process object in a Node.js program?

A

It is global, so you can just type it in to access it

163
Q

What is the data type of process.argv in Node.js?

A

Array of strings

164
Q

What is a JavaScript module?

A

A single JavaScript file

165
Q

What values are passed into a Node.js module’s local scope?

A

Exports, require, module, __filename, __dirname

166
Q

Give two examples of truly global variables in a Node.js program.

A

Process object, setTimeout() function

167
Q

What is the purpose of module.exports in a Node.js module?

A

Allows code to be stored in the module object, so it can be transferred to another module

168
Q

How do you import functionality into a Node.js module from another Node.js module?

A

Use the require() function

169
Q

What is the JavaScript Event Loop?

A

A process which allows for asynchronous javascript coding.

Involves interactions between the js stack, web apis, and the task queue

170
Q

What module does Node.js include for manipulating the file system?

A

fs

171
Q

What method is available in the Node.js fs module for writing data to a file?

A

The writefile method

172
Q

Are file operations using the fs module synchronous or asynchronous?

A

Asynchronous (and synchronous if sync version of method is being used)

173
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET

174
Q

What is on the first line of an HTTP request message?

A

The start line, which contains an http method, the request target, and the http version

175
Q

What is on the first line of an HTTP response message?

A

The status line, which contains the protocol version, a status code, and a status text

176
Q

What are HTTP headers?

A

A case sensitive string followed by a colon and a value all of which is on one line.
Provides different information depending on if it is a response header or a request header.

177
Q

Is a body required for a valid HTTP message?

A

No

178
Q

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

Application / json

179
Q

What is the significance of an HTTP request’s method?

A

Determines what type of request is sent to the server, which communicates the intended action being performed

180
Q

What does the express.json() middleware do and when would you need it?

A
  • It parses json strings and creates a body object containing the parsed data and attaches it to the request object
  • You need it in order to post new data to a server, by passing it through the app object using the use method
181
Q

What are the three states a Promise can be in?

A
  • pending: initial state, neither fulfilled nor rejected
  • fulfilled: meaning that the operation was completed successfully
  • rejected: meaning that the operation failed
182
Q

How do you handle the fulfillment of a Promise?

A

The then method

183
Q

How do you handle the rejection of a Promise?

A

The catch method

184
Q

What is Array.prototype.filter useful for?

A
  • Quickly creating new arrays that contain filtered items
  • Instead of creating a loop, you can just write out a simple callback
185
Q

What is Array.prototype.map useful for?

A
  • Quickly manipulating an entire array with a simple function
  • For example, you can create a React component for each item in an array using the map method
186
Q

What is Array.prototype.reduce useful for?

A
  • It reduces the items in an array into a single value through a callback function using an accumulator variable
  • With each iteration, the accumulator value can be modified until there are no more items in the array and the accumulator value is returned
187
Q

What is the typeof an ES6 class?

A
188
Q

Describe ES6 class syntax.

A
189
Q

What is “refactoring”?

A

Re-writing old code in a more concise or updated manner.

190
Q

How are ES Modules different from CommonJS modules?

A
  • More compact syntax
  • Structure can be statically analyzed
  • Better support for cyclic dependencies
191
Q

What must the return value of myFunction be if the following expression is possible?

myFunction()();

A
192
Q

What does this code do?

const wrap = value => () => value;

A
193
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A
194
Q

What allows JavaScript functions to “remember” values from their surroundings?

A