JavaScript Flashcards

1
Q

What is the purpose of variables?

A

variables give us permanents (store data to use later)

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

How do you declare a variable?

A

type the keyword var, let, const

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

How do you initialize (assign a value to) a variable?

A

use a single =

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

What characters are allowed in variable names?

A

letter, dollar sign, underscore, and numbers

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

What does it mean to say that variable names are “case sensitive”?

A

lowercase & uppercase matters in JS

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

What is the purpose of a string?

A

characters (store texts)

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

What is the purpose of a number?

A

calculations, any math related value

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

What is the purpose of a boolean?

A

potential to have logic (binary statement)

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

What does the = operator mean in JavaScript?

A

assignment operator (to put a value)

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

How do you update the value of a variable?

A

only write the variable name (without rewriting var)

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

What is the difference between null and undefined?

A

null is an assigned value. (made to be empty on purpose)

undefined means a variable has been declared but not defined yet.

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

makes it easier to debug

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

Give five examples of JavaScript primitives.

A

string, number, boolean, null, undefined, objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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
15
Q

What is string concatenation?

A

addition for strings

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

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

A

add values or concatenate strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
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
18
Q

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

A

allows you to add numbers or strings to an existing variable

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

What are objects used for?

A

grouping of data

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

What are object properties?

A

variables within a certain boundaries

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

Describe object literal notation.

A

variable = {

property: value }

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

How do you remove a property from an object?

A

delete operator

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

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

A

dot notation, bracket notation

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

What are arrays used for?

A

store set of orders

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

Describe array literal notation.

A

[ set of values stored, separated by comma ]

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

How are arrays different from “plain” objects?

A

they have orders, square brackets, not individually named

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
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
28
Q

What is the length property of an array?

A

total number of items inside an array

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

How do you calculate the last index of an array?

A

subtract one from length

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

What is a function in JavaScript?

A

reusable statement for tasks

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

Describe the parts of a function definition.

A

parameter, function keyword, function code block

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

Describe the parts of a function call.

A

name of the function, parenthesis, and arguments

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

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

A

definitions: keyword, code block, parameters
call: arguments

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

What is the difference between a parameter and an argument?

A

parameter: placeholder for argument
argument: actual value for function to be called

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

Why are function parameters useful?

A

without it, the function’s end result is always the same

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

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

A
  1. exits the code block

2. gives a value

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

Why do we log things to the console?

A

debugging tool

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

What is a method?

A

methods are functions stored into the property of an object.

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

How is a method different from any other function?

A

stored into the property of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
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
41
Q

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

A

math.floor

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

How do you generate a random number?

A

math.random

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
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
44
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
45
Q

How do you break a string up into an array?

A

split method

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

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

A

they do not change the original. Check by using console.log()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
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
48
Q

Roughly how many array methods are there according to the MDN Web docs?

A

25

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

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

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

Give 6 examples of comparison operators.

A

, >=, <=, ==, ===

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

What data type do comparison expressions evaluate to?

A

boolean

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

What is the purpose of an if statement?

A

add conditions to the code

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

Is else required in order to use an if statement?

A

no

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

Describe the syntax (structure) of an if statement.

A

if, condition, {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
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
56
Q

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

A

use logical and or logical or

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

What is the purpose of a loop?

A

to perform repeated task

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

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

A

if it s true, it continues, if it s false, it stops

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

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

A

one repetition of the code block loop

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

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

A

before the code block runs

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

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

A

very beginning (before anything)

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

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

A

before each iteration

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

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

A

after each iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
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
65
Q

What does the ++ increment operator do?

A

increments variable by 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
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
67
Q

Why do we log things to the console?

A

to check if the code is working, to make debugging easier

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

What is a “model”?

A

representation of something

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

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

A

HTML doc

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

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

A

data type in javascript

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

What is a DOM Tree?

A

model of the page when a browser loads a web page.

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

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

A

document.getElementById(), document.querySelector()

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

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

A

document.querySelectorAll()

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

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

A

if you want to access it multiple times

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

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

A

dir method

directory

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

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

A

so that it runs after all the information on HTML document

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

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

A

css selector as an argument (String)

first element in HTML doc that matches

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

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

A

css selector as argument

returns nodelist

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

Why do we log things to the console?

A

To check the process and values. Verifying if something actually happened.

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

What is the purpose of events and event handling?

A

event handling = creating code the handle the event

event = things that happen

81
Q

Are all possible parameters required to use a JavaScript method or function?

A

No.

82
Q

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

A

addEventListener

83
Q

What is a callback function?

A

function definition being passed in as an argument

84
Q

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

A

Event object

85
Q

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

A

property on event object whose value is whatever element that event originated at.

86
Q

What is the difference between these two snippets of code?

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

A

top: handleClick is being referenced
bottom: handleClick is being called (never use)

87
Q

What is the className property of element objects?

A

gets and sets the value of the class attribute of the specified element.

88
Q

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

A

use queryselector and class name property

89
Q

What is the textContent property of element objects?

A

get the value of the current text element and update

90
Q

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

A

queryselect the element and get whatever the new value is and assign it to textcontent property

91
Q

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

A

no

92
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

more complicated

93
Q

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

A

it makes it easier to make sense.

94
Q

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

A

focus event

95
Q

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

A

blur event

96
Q

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

A

input event

97
Q

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

A

submit event

98
Q

What does the event.preventDefault() method do?

A

Prevents default behavior

99
Q

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

A

reloads/refreshes the page

100
Q

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

A

elements property

101
Q

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

A

value property

102
Q

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

A

hard to see where the code went wrong

103
Q

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

A

to see if your code is working, check variable values, etc.

104
Q

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

A

no, it just makes them. does not inset until appendchild method is used.

105
Q

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

A

appendchild method or append method

106
Q

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

A

name and value

107
Q

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

A

createElement and appendChild()

108
Q

What is the textContent property of an element object for?

A

To get text content or to set the text content of an element

109
Q

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

A

Element.setAttribute( )

Element.className

110
Q

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

A

Defining a function allows for reusability so you don’t have to write the function over and over. Defined functions are also easy to test.

111
Q

What is the event.target?

A

Object that the event is working on

112
Q

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

A

event bubbles all the way up to the parent element (the document and then the window).

113
Q

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

A

The tagName property

114
Q

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

A

It takes in a css selector as an argument and returns the closest parent

115
Q

How can you remove an element from the DOM?

A

remove( ) method

116
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

Add the event listener to parent

117
Q

What is the event.target?

A

property on event object whose value is whatever element that event originated at.

118
Q

What is the affect of setting an element to display: none?

A

The element won’t be displayed because it won’t get rendered. The document will treat it as if it didn’t exist along with child elements.

119
Q

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

A

Takes a css selector as a string for an argument and returns a Boolean value

120
Q

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

A

getAttributes( ) method

121
Q

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

A

Anytime you want to verify a value or to verify if the code is working correctly.

122
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

The code would have to have multiple conditions for each tab.
(event handler for every single tab)

123
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

It would be written by adding new event listener and possibly new event handler function for each tab.

124
Q

What is JSON?

A

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax.

125
Q

What are serialization and deserialization?

A

Serialization: converting complex data (like an object) to string
Deserialization: converting string to object

126
Q

Why are serialization and deserialization useful?

A

Serialization allows from data to be stored in memory. Also makes it easier to transfer data across a network.
Deserialization makes it so that data is easier to interact with.

127
Q

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

A

JSON.stringify( )

128
Q

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

A

JSON.parse( )

129
Q

How to you store data in localStorage?

A

localStorage.setItem( ) method

130
Q

How to you retrieve data from localStorage?

A

localStorage.getItem( ) method

131
Q

What data type can localStorage save in the browser?

A

‘String’ type data (local storage needs serialized data )

132
Q

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

A

Before the page unloads

133
Q

What is a method?

A

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

134
Q

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

A

A method definition would have the keyword function and { } for the function code block.
A method call would have the object followed by dot notation, name of method and then ( ).

135
Q

Describe method definition syntax (structure).

A

{ property: function methodName ( [optional parameters] ) {code block }, }

136
Q

Describe method call syntax (structure).

A

object.methodName( )

137
Q

How is a method different from any other function?

A

Needs dot notation or bracket notation. Also a method belongs to an object as a property of the object.

138
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain BOTH data (as properties) and behavior (as methods)

139
Q

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

A

Abstraction, encapsulation, inheritance , polymorphism

140
Q

What is “abstraction”?

A

It is a process that enables a user to work with (possibly) complex things in simply ways.

141
Q

What does API stand for?

A

Application Programming Interface

142
Q

What is the purpose of an API?

A

Selection of tools (set of code features such as methods, properties, events, and URLS) to make it easier for developers to interact with a software.

143
Q

What is this in JavaScript?

A

‘this’ is an implicit parameter of all JavaScript functions.

144
Q

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

A

It is available in a function’s code block even though it was never included in the function’s parameters list or declared with ‘var’.

145
Q

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

A

call time

146
Q
What does this refer to in the following code snippet?
var character = {
firstName: 'Mario',
greet: function ( ) {
var message = 'It\'s-a-me, ' + this.firstName + '!';
console.log(message);
}
};
A

Nothing. The value of ‘this’ can only be determined during call time (not during a function definition).

147
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

Result = “It’s-a-me, Mario!” because ‘this’ refers to the object being called. The object firstName property has the value of Mario.

148
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

Result = “It’s-a-me, undefined!” because ‘this’ refers to the window (hello is not a property of an object, therefore default object would be the window object). Window object does not have the property firstName so therefore, ‘this.firstName” has the value of undefined.

149
Q

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

A

You can’t. Value of ‘this’ is determined at call time.

150
Q

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

A

By looking to the left of the dot (the object).

151
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance

152
Q

What is a prototype in JavaScript?

A

move properties and methods that we’d like to reuse into a “prototype” object and then tell other objects to simply delegate (verb) to that “prototype” object when they aren’t able to perform the required tasks themselves.

153
Q

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

A

Due to JS prototypes; models that was created that contain these methods.

154
Q

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

A

From the object’s prototype, if it’s not there then object’s object’s prototype

155
Q

What does the new operator do?

A

Creates a blank, plain JavaScript object

Links (sets the constructor of) the newly created object to another object by setting the other object as its parent prototype;

Passes the newly created object from Step 1 as the this context;

Returns this if the function doesn’t return an object.

156
Q

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

A

Prototype property

157
Q

What does the instanceof operator do?

A

It tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. Returns a boolean.

158
Q

What is a “callback” function?

A

It is a function passed in through another function as an argument

159
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

160
Q

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

A

setInterval() function

161
Q

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

A

0

162
Q

What do setTimeout() and setInterval() return?

A

setTimeout( ): The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout( )
setInterval( ): The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval( )

163
Q

What is AJAX?

A

Is a technique for loading data into part of a page without having to refresh the entire page.

164
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

165
Q

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

A

XMLHttpRequest

166
Q

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

A

load event

167
Q

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

A

They share a prototype. Both are chained to the EventTarget Prototype

168
Q

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

A

A block of code within curly braces { };

Examples: if else, for, do while, while; function code block;

169
Q

What does block scope mean?

A

An area within the block where variables can be referenced

170
Q

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

A
Let = block-scoped;
Const = block-scoped
171
Q

What is the difference between let and const?

A

Const can’t be reassigned while let can. Both cannot be redeclared.

172
Q

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

A

The value within the array is mutable

173
Q

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

A

If the variable is not going to be reassigned, use ‘const’. If it will be reassigned, then use ‘let’

174
Q

What is the syntax for writing a template literal?

A

Template literals use backticks rather than single or double quotes and the javascript expression is as follows: ${variable}

175
Q

What is “string interpolation”?

A

A process where variables and expressions is embedded in a string. The variable/expression has to be placed in a space block as follows:
${variable_name}

176
Q

What is destructuring, conceptually?

A

Taking the values within the object and assign it to a variable

177
Q

What is the syntax for Object destructuring?

A

let {
property1: variable1,
property2: variable2
} = object;

178
Q

What is the syntax for Array destructuring?

A

let [index1, index 2] = array

179
Q

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

A

Destructuring: variable name goes on the right of the assign operator ( let/const { } or [ ] = variable )
Creating: variable name goes on the left of the assign operator ( variable = { } or [ ])

180
Q

What is the syntax for defining an arrow function?

A

(parameters separated by commas) => { code block };

If there is only 1 parameter, the parentheses are not needed. If return is a simple expression, brackets and return keyword can be omitted. Brackets and return keyword are needed for code block if it’s multiline statements.

181
Q

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

A

Body becomes a return.

182
Q

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

A

Arrow functions: value of this is determined at definition time
Regular functions: value of this is determined at call time

183
Q

What is the JavaScript Event Loop?

A

The Event Loop is a queue of callback functions. Takes the first thing on the callback queue and puts it back on the stack if the stack is empty

184
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

Blocking is when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes.
Non-blocking methods execute asynchronously.

185
Q

How do you mount a middleware with an Express application?

A

By app.use()

186
Q

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

Request object, response object

187
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.
188
Q

How do you handle the fulfillment of a Promise?

A

Use then( ) method

189
Q

How do you handle the rejection of a Promise?

A

Use then( ) method or catch( ) method

190
Q

What is Array.prototype.filter useful for?

A

The filter() method creates a new array with all elements that pass the test implemented by the provided function.

191
Q

What is “syntactic sugar”?

A

Is syntax within a programming language that is designed to make things easier to read or to express.

It makes the language “sweeter” for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

192
Q

What is the typeof an ‘ES6 class’?

A

function

193
Q

Describe ES6 class syntax.

A
Class keyword followed by curly braces for the class declaration
constructor (parameter)
194
Q

What is “refactoring”?

A

Code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior; preserve functionality

195
Q

How are ES Modules different from CommonJS modules?

A

ES modules are the standard for JavaScript, while CommonJS is the default in Node. js.

196
Q

What does fetch() return?

A

returns a promise containing the response (a Response object).

197
Q

What is the default request method used by fetch()?

A

GET

198
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

use method: