JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Variables are used to represent values/store information that can be used in your code.

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

How do you declare a variable?

A

by using the keyword var followed by a name to represent your variable.

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

By using the assignment operator followed by a value

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

letters, numbers, dollar signs, or underscores. However, the name can NOT start with a number

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

variables names are sensitive to the capitalization of letters. Example: var keyword and var keyWord are two different variables.

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

a string is a data. type that is represented using characters and text.

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

a number is a data type represented by numbers and is used for calculating values. Used to store numeric values.

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

a boolean is a data type that only has two values: true and false. Good for logical reasoning

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. assigns values to avaraibles

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

by taking the variable name and assigning it a new value with he assignment operator, So long as this line of code comes after the initial value assignment.

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 intentionally assigned an empty value and its type is an object, whereas undefined can be unintentional and means a variable has been declared but not assigned a value 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

So you know what variable/information you are logging to the console.

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

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

adding two strings together into one variable using + operator

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

addition or concatenation

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

adds a value to the variables original value.

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

What are objects used for?

A

objects are used for storing multiple values.

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

What are object properties?

A

object properties are variables that are stored within an object.

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

Describe object literal notation.

A

object literal notation involves a set of curly braces holding a comma separated list of properties and methods to which is being stored in a variable.

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

by using the delete operator(keyword) on the object

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 and 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

For storing lists of data

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

Describe array literal notation.

A

brackets with data types separated by commas. All assigned into a variable.

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

arrays have index numbers whereas objects have property names

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

the length property gives you the number of items in 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

array.length - 1

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

What is a function in JavaScript?

A

a javascript function is an object that can be called to perform a task.

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

function keyword, optional name, a comma separated list of at least 0 parameters wrapped in ( ), and definition 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

function name followed by parenthesis containing any 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

the function definition includes the function keyword, function name, parameters, and definition block.

the function call only has the function name and 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

parameters are for definitions whereas arguments are passed when the function is called.

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

Why are function parameters useful?

A

parameters are placeholders for data that will be collected when the function is called.

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

returns a value from the definition block and ends the function.

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

to ensure our code is producing the right outputs. To check our work. Too visualize what the code is doing and identify mistakes if any.

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

What is a method?

A

A function that is being applied to 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

Methods are associated with objects and have special access to information stored in its 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

floor method of the Math object

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

random method of the Math object

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

pop, shift, or 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

No. log variables to the console to check.

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

Give 6 examples of comparison operators.

A

less than, greater than, less than or equal to, greater than or equal to, not equal to, strictly equal to.

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

What data type do comparison expressions evaluate to?

A

booleans

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

What is the purpose of an if statement?

A

to check if a given condition is true or false, and if so, run code based on the condition.

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

Describe the syntax (structure) of an if statement.

A

if keyword, condition statement, code block

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

What are the three logical operators?

A

&&, ||, !

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

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

A

by wrapping the expressions in parenthesis

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

What is the purpose of a loop?

A

to repeat a piece of code a number of times

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

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

A

A condition allows for a piece of code to run repeatedly until the condition evaluates as false, then the loop will stop.

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

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

A

An iteration is a single execution of a code block in a loop.

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

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

A

Before each execution of its code block.

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

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

A

The initialization gets evaluated once at the very beginning of the loop. Also comes before the condition.

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

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

A

right before each loop iteration.

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

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

A

at the end of each loop iteration.

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

What does the ++ increment operator do?

A

increase by 1

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

How do you iterate through the keys of an object?

A

for…in loop

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

Why do we log things to the console?

A

For debugging and checking values.

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

What is a “model”?

A

It is a representation of something.

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

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

A

The html document being displayed by the browser.

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

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

A

Object refers to all the objects that make up the document.

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

What is a DOM Tree?

A

The DOM tree is the structure in which the browser creates a model of the document,

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

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

A

.querySelector() and .getElementById()

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

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

A

.querySelectorAll()

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

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

A

For reusability.

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

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

A

So the DOM has time to load before running any javascript.

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

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

A

it takes a css selector in the form of a string and returns the FIRST element matching the selector.

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

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

A

it takes a css selector in the form of a string and returns ALL elements(node list) matching the selector.

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

What is the purpose of events and event handling?

A

Events and event handling allow for a web page to respond to a user interaction

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

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

A

They indicate that a parameter is optional

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

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

A

.addEventListener(‘event’, functionName);

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

What is a callback function?

A

A call back function is a function that is passed into another function as an argument.

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

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

A

The Event Object.

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

What is the event.target?

A

the target property of the event object is a reference to the element that the event was dispatched on.

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

What is the className property of element objects?

A

The className property is a property that allows you to access and set a value for the class name attribute of an element.

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

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

A

With className property.

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

What is the textContent property of element objects?

A

textContent property is a property that represents an elements text content.

86
Q

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

A

By using .textContent property.

87
Q

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

A

no.

88
Q

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

A

focus event.

89
Q

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

A

blur event

90
Q

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

A

input event

91
Q

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

A

submit event

92
Q

What does the event.preventDefault() method do?

A

prevents the default function of an element.

93
Q

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

A

reloads the web page

94
Q

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

A

elements property

95
Q

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

A

value property

96
Q

What is one risk of writing a lot of code without checking to see if it works along the way?

A

You risk making debugging very difficult

97
Q

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

A

check and debug your program in real time.

98
Q

What is JSON?

A

JSON stands for JavaScript Object Notation and it is a text based data format that is very similar to object notation.

99
Q

What are serialization and deserialization?

A

Serialization is the process of converting an object into a stream of bytes so it can be transferred over a network.

deserialization is the process of converting a stream of bytes into an object.

100
Q

Why are serialization and deserialization useful?

A

Sending information over a network.

101
Q

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

A

JSON.stringify();

102
Q

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

A

JSON.parse();

103
Q

How do you store data in localStorage?

A

call the setItem method of the localStorage object.

104
Q

How to you retrieve data from localStorage?

A

call the getItem method of the localStorage object.

105
Q

What data type can localStorage save in the browser?

A

key/value pairs in the form of strings.

106
Q

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

A

just before the program closes, while the content is still visible.

107
Q

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

A

No, it only creates an element, but does not insert it into the page. .

108
Q

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

A

appendChild method

109
Q

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

A

you pass two string representing an attribute and its value

110
Q

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

A

create the element, give the element some content, and insert the element into the page.

111
Q

What is the textContent property of an element object for?

A

The textContent property is used to get or set the text content of an element.

112
Q

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

A

.className property or .setAttribute method

113
Q

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

A

It can be reused to create new elements in different parts of the code.

114
Q

What is the event.target?

A

The target method of the event object is a reference to the object that the event was fired on

115
Q

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

A

Event Bubbling.

116
Q

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

A

.tagName property.

117
Q

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

A

It takes a selector for its argument and return the first matching ancestor element.

118
Q

How can you remove an element from the DOM?

A

.remove() method.

119
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

adding an eventListener to an ancestor element.

120
Q

What is the event.target?

A

The target property of the Event object is a reference to the object onto which the event was dispatched.

121
Q

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

A

It hides and removes the element from the document flow.

122
Q

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

A

Its takes in a css selector in the form of a string and returns a boolean stating whether the object matches the selector.

123
Q

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

A

GetAttribute method

124
Q

What is a method?

A

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

125
Q

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

A

a method call is attached to an object by a period whereas a method definition is stored inside an objects code block

126
Q

Describe method definition syntax (structure).

A

property name, followed by function keyword with a set of parenthesis containing a comma separated list of parameters, followed by the definition block.

127
Q

Describe method call syntax (structure).

A

object name, followed by method name with a set of parenthesis containing a comma separated list of arguments.

128
Q

How is a method different from any other function?

A

a method is a function that is stored inside a property in an object and has special access to that objects data.

129
Q

What is the defining characteristic of Object-Oriented Programming?

A

Its use of objects to store data and to have these objects interact with themselves and other objects. (pairs data with behavior)

130
Q

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

A

abstraction, encapsulation, inheritance, and polymorphism

131
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways.

132
Q

What does API stand for?

A

Application Programming Interface

133
Q

What is the purpose of an API?

A

An API give programmers a way to interact with a system in a simple way. They allow a programmers to request and receive data. They also allow different apps or services to interact with each other in various ways.

134
Q

What is ‘this’ in JavaScript?

A

this refers the the object it was called on. It is an implicit parameter for all methods.

135
Q

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

A

This is always there. It does not to be declared as a parameter.

136
Q

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

A

call time.

137
Q

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

A

You can not know until it is being called.

138
Q

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

A

You can tell what this is by looking to the left of the dot on the method call. If there is no dot, this refers to the window object.

139
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance.

140
Q

What is a prototype in JavaScript?

A

a prototype is an object that contains reusable properties and methods that other objects can delegate tasks too.

141
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

When these data types are created, they inherit these properties from the window through the __proto__ property. (Prototypes make it possible).

142
Q

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

A

the proto-object.

143
Q

What does the new operator do?

A

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function. (Creates an object, attaches a proto property to that object, and returns this. )

144
Q

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

A

__proto__ property

145
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. The return value is a boolean value.

146
Q

What is a “callback” function?

A

A callback function is a function that is being passed into another function as an argument.

147
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() method.

148
Q

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

A

setInterval() method.

149
Q

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

A

0

150
Q

What do setTimeout() and setInterval() return

A

They return a timeoutID which is a positive integer that identifies the timer made by the setTimeout or setInterval method.

151
Q

What is a client?

A

it is the service requester in the client-server model

152
Q

What is a server?

A

it is the service/resource provider in the client-server model

153
Q

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

A

get method

154
Q

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

A

An http method, a request target, and the HTTP version.

155
Q

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

A

The protocol version, a status code, and status text

156
Q

What are HTTP headers?

A

HTTP headers are optional lines of text that specify the request or describe the body included in the message.

157
Q

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

A

MDN?

158
Q

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

A

No

159
Q

What is AJAX?

A

Ajax is a technique for loading data into part of a page without it having to refresh the entire page

160
Q

What does the AJAX acronym stand for?

A

Asynchronous Javascript And XML

161
Q

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

A

XMLHttpRequest()

162
Q

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

A

load event

163
Q

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

A

Ac ode block is a set of code that is grouped together, usually by using {}. Funcitons, loops, and conditionals have code blocks.

164
Q

What does block scope mean?

A

Block scope refers to the local scope of a given code block. Variables declared in a function are part of the function scope, but variables declared inside of a conditional that is stored inside of a function, only have access to its code block scope.

165
Q

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

A

block scope

166
Q

What is the difference between let and const?

A

Let is mutable whereas const is immutable. Let can be reassigned a value whereas you cannot be reassign.

167
Q

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

A

Arrays are mutable and its contents can be changed. Is is the variable that cannot be assigned an entirely new value

168
Q

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

A

Never use variable. Favor const but generally use const for variables that will not change and let for variables that will be updated over time. But only use let if const is not possible.

169
Q

What is the syntax for writing a template literal?

A

Wrapp string in backticks and use ${} to pass variables into the string.

170
Q

What is ‘string interpolation’ ?

A

String interpolation is the process of evaluating a string that contains one or more placeholders(variables), which will be replaced by their appropriate values when the string is evaluated.

171
Q

What is the syntax for defining an arrow function?

A

() => {}. Parenthesis are needed only when using 0 or more than one parameters. Curly braces can be left off and if so, no return keyword is needed.

172
Q

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

A

No return keyword is needed

173
Q

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

A

Regular functions: this is determined at call time. Arrow functions are determined at definition time.

174
Q

What is Node js?

A

Node js is a runtime environment that allows you to run javascript outside of the browser.

175
Q

What can Node.js be used for?

A

To run javascript outside of the browser for things such as building back ends for Web applications, command-line programs, or any kind of automation

176
Q

What is a REPL?

A

REPL stands for read-evaluate-print-loop. This is an environment that takes single user inputs, executes them, and returns the result to the user. Just like Chrome DevTools Console

177
Q

What is a JavaScript module?

A

A JavaScript module is a single JavaScript file

178
Q

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

A

export, module, require(), __filename, __dirname

179
Q

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

A

process and global.

180
Q

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

A

The purpose of module.exports is to ‘export’ functionality from a node module so another module can access its functionality.

181
Q

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

A

By calling the require function and passing relative path as its argument.

182
Q

What is a directory?

A

A directory is a file system that allows a user to group files together.

183
Q

What is a relative file path?

A

a relative file path is a path to file from the current directory.

184
Q

What is an absolute file path?

A

an absolute file path is path from a systems root directory.

185
Q

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

A

fs

186
Q

What is the JavaScript Event Loop?

A

The event loop is in charge of checking the call stack and if the call stock is available, it will place a queue task in the call stack.

187
Q

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

A

blocking functions execute in a series whereas non-blocking functions execute concurrently.

188
Q

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

A

fs.writeFile

189
Q

Are file operations using the fs module synchronous or asynchronous?

A

Both

190
Q

What is NPM?

A

NPM is a package manager and the worlds largest software directory. Trick Question: NPM can refer to command line interface, website, or registry.

191
Q

What is a package?

A

Packages are bits of reusable code that programmers can share so that other programmers can use those pieces of code in their own projects. A directory with one or more files but must include a package.json

192
Q

How can you create a package.json with npm?

A

npm init -y

193
Q

What happens when you add a dependency to a package with npm?

A

It will get added to the package.json and a node module directory will get added to the current directory.

194
Q

How do you add express to your package dependencies?

A

npm install express

195
Q

What Express application method starts the server and binds it to a network PORT?

A

.listen method

196
Q

How do you mount a middleware with an Express application?

A

use method

197
Q

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

A

The request and response objects

198
Q

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

A

application/json; charset=utf-8

199
Q

What is Array.prototype.filter useful for?

A

To create a new array excluding certain elements

200
Q

What is Array.prototype.map useful for?

A

For creating a new array of transformed elements

201
Q

What is Array.prototype.reduce useful for?

A

For condensing all elements in an array to a single value

202
Q

What is “syntactic sugar”?

A

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

203
Q

What is the typeof an ES6 class?

A

Function

204
Q

Describe ES6 class syntax.

A

class keyword, class name, code block

205
Q

What is “refactoring”?

A

The process of restructuring already existing code without changing its behavior.

206
Q

How are ES Modules different from CommonJS modules?

A

ES module syntax is more compact,

207
Q

What does express.static() return?

A

a middleware function.

208
Q

What is the local __dirname variable in a Node.js module?

A

the __dirname variable give you an absolute path to the current working directory

209
Q

What does the join() method of Node’s path module do?

A

the join method of the Node’s path module joins all given path segments together

210
Q

What does fetch() return?

A

A promise that resolves to a response object

211
Q

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

A

GET

212
Q

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

A

by passing an init object with a method property.