javascript Flashcards

1
Q

What is the purpose of variables?

A

To store data

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

How do you declare a variable?

A

A variable keyword and then the variable name

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

Using the assignment operator (=)

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 sign, or an underscore

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

You can reuse the same name with different capitalization

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

Holding data in text form

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

For tasks involving counting or calculating and to store numerical data

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

To store data as either a yes or no (lightswitch); yes it should do this or no it should not

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; Assign a value to a variable

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

Using the assignment operator

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

Undefined is a type while null is an object; Undefined is a variable that has been declared but the value has not

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

To help keep track of what you are console logging

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, undefined, null, boolean

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

Numbers

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

What is string concatenation?

A

Combining two 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

To add numbers and 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

Concatenates and assigns the new value to the original variable

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

What are objects used for?

A

To store properties and their values. They are meant to model real world objects.

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

What are object properties?

A

They tell us about the object (such as the name of a hotel)

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

Describe object literal notation.

A
You create an object by defining the key value pairs and assign it to a variable
var student = {
name = Shawn
}
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

Using the 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

Lists

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

Describe array literal notation.

A

Using the square brackets

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 are indexed numerically

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

Shows you numerically the length of the 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

arrayName.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

Combining multiple lines of code into a function for ease of access and readability

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

The function keyword along with an optional name and a parameter surrounded by parenthesis and then an opening and closing curly brace

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

The functions name with an argument surrounded by parenthesis

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 parameter becomes an argument and you don’t need the curly braces

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

A parameter is defined with the function, while an argument is passes when calling a function

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

Why are function parameters useful?

A

To store and pass data and provide extra information about the function

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

Causes the code block within the function to be ran, and prevents more code from being run.

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

So we can see what’s actually happening with our code.

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

What is a method?

A

A method is a function which is a 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

A method is associated with 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

Round method

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 method

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

No; console log

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

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

A

50

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

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

A

37

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

Give 6 examples of comparison operators.

A

> ; =; <=; ===; !===

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

What is the purpose of an if statement?

A

To make decisions on which code to run

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

Describe the syntax (structure) of an if statement.

A

Keyword, then condition, then opening curly brace, the code you want to run, and then a closing curly brace.

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

What are the three logical operators?

A

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

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

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

A

Logical operators

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

What is the purpose of a loop?

A

To keep checking conditions until a statement is true.

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

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

A

Setting how long the loop should run

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

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

A

Each time a loop runs

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

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

A

Before the statement is executed

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

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

A

Before the condition

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

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

A

After the initialization and before the final-expression

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

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

A

After the condition

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

How do you iterate through the keys of an object?

A

For-in loops

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

Why do we log things to the console?

A

So we can see what’s actually happening.

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

What is a “model”?

A

A recreation of something

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

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

A

The current html document you are working on

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

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

A

Represents the different objects within the DOM

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

What is a DOM Tree?

A

A model of a web page

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

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

A

getElementById() and querySelector()

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

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

A

To store the location of the element. This way the DOM doesn’t have to search through the DOM Tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
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
77
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 loaded after all the HTML content

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

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

A

It takes a css selector and returns only the first of the matching elements

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

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

A

It takes a css selector and returns all elements that match

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

Why do we log things to the console?

A

To see what data is being passed

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

What is the purpose of events and event handling?

A

To run code based off of things that happen on the web page

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

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

A

It means the argument is optional

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

What is a callback function?

A

A function passed into another function as an argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
85
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
86
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 place where the event is being invoked, and in the debugger.

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

What is the difference between these two snippets of code?

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

A

The second one will run as soon as it hits the line of code, instead of when the event occurs

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

What is the className property of element objects?

A

the string within the class attribute

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

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

A

Using the className property

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

What is the textContent property of element objects?

A

the text content of the node and its decendants

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

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

A

Useful but not necessary

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

Harder

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

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

A

So you can access it again quickly and so you don’t depend on the DOM.

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

How do you update the text within an element?

A

Select the element and use the textContent property

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
95
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
96
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
97
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
98
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
99
Q

What does the event.preventDefault() method do?

A

Prevents the default event of whatever it’s in

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

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

A

Reloads the page after you submit

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

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

A

.elements property

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

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

A

.value property

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

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

A

It makes it a lot harder to debug

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

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

A

You can see what’s happening at all times

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

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

A

No

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

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

A

appendChild() method

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

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

A

The attribute name then the value

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

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

A

Create the element, give it content, and add it to the dom

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

What is the textContent property of an element object for?

A

To change the text content of that element

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

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

A

setAttribute() and className() methods

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

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

A

You can reuse the function later & so you don’t repeat yourself

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

What is the event.target?

A

The element interacted with during an event

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

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

A

Event flow makes it possible. You are clicking on an element that is within another element (event bubbling)

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

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

A

tagName

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

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

A

It takes the selector and returns itself or the closest element to the selector

116
Q

How can you remove an element from the DOM?

A

The remove method. element.remove()

117
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 an event listener to the parent element

118
Q

What is the event.target?

A

The element interacted with during an event

119
Q

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

A

The document renders as if the element doesn’t exist

120
Q

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

A

It takes a selector, and returns a boolean

121
Q

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

A

getAttribute()

122
Q

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

A

All steps

123
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

Multiple event listeners

124
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

Multiple conditional statements

125
Q

What is JSON?

A

Text-based data format following JavaScript object syntax

126
Q

What are serialization and deserialization?

A

Deserialization is when you convert a string to a native object, and serialization is when you convert an object to a string.

127
Q

Why are serialization and deserialization useful?

A

It allows us to transmit data

128
Q

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

A

Stringify

129
Q

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

A

Parse

130
Q

How to you store data in localStorage?

A

setItem() method

131
Q

How to you retrieve data from localStorage?

A

getItem() method

132
Q

What data type can localStorage save in the browser?

A

String

133
Q

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

A

Before everything is dumped out of the memory from the browser.

134
Q

What is a method?

A

A function which is a property of an object.

135
Q

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

A

A method definition is when you give a method functionality whereas a method call you are returning the functionality of that property onto an object.

136
Q

Describe method definition syntax (structure).

A

You define a method like you would an object property and then give it the function to run whatever code you want.

137
Q

Describe method call syntax (structure).

A

object.Method(). You attach the method to the object and return the result.

138
Q

How is a method different from any other function?

A

A method is a property of an object

139
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

140
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

141
Q

What is “abstraction”?

A

Being able to work with possibly complex things in simple ways.

142
Q

What does API stand for?

A

Application programming interface

143
Q

What is the purpose of an API?

A

Give programmers a way to interact with a system in a simplified, consistent fashion

144
Q

What is this in JavaScript?

A

this is an implicit parameter of all JavaScript functions.

145
Q

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

A

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

146
Q

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

A

call time

147
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

The character object

148
Q

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

A

It returns the message variable because it runs the greet method because the greet method is being called on the character object,

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

It returns the message + undefined because this.firstName isn’t defined within the variable hello. This keyword is now attached to hello rather than the firstName property of the character object.

150
Q

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

A

By default it will refer to the object in which it was created

151
Q

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

A

To whatever object calls the function

152
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based or prototypal

153
Q

What is a prototype in JavaScript?

A

a JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects.

154
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

Those methods are defined on a “prototype” object and arrays simply borrow those methods when they’re needed.

155
Q

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

A

The prototype chain

156
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.

157
Q

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

A

Prototype

158
Q

What does the instanceof operator do?

A

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.

159
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

160
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()

161
Q

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

A

setInterval()

162
Q

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

A

0

163
Q

What do setTimeout() and setInterval() return?

A

A timeout or interval ID which is an integer

164
Q

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

A

Grouped statements within a curly brace, if else, for, while

165
Q

What does block scope mean?

A

It refers to the lines of code within the code block

166
Q

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

A

Block scope

167
Q

What is the difference between let and const?

A

You can reassign values to variables with let, while you can’t do that with const

168
Q

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

A

Because you’re adding to the array rather than re-assigning or re-declaring

169
Q

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

A

You should use const unless you need to reassign the variable later

170
Q

What is destructuring, conceptually?

A

Unpacking values into variables

171
Q

What is the syntax for Object destructuring?

A

const {name, name, name} = objectVariable

172
Q

What is the syntax for Array destructuring?

A

const [name, name, name] = arrayVariable

173
Q

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

A

If it’s happening on the left side of the equal sign its destructuring

174
Q

What is the syntax for writing a template literal?

A

${variableName}

175
Q

What is “string interpolation”?

A

The ability to substitute part of the string for the values of variables or expressions.

176
Q

What is the syntax for defining an arrow function?

A

const = (p1, p2, …, pn) => expression

or

const = (p1,p2,..,pn) => {}

177
Q

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

A

It doesn’t need a return statement

178
Q

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

A

This will be referring to the enclosing context, rather than creating its own context within the function

179
Q

What is a CLI?

A

Command line interface

180
Q

What is a GUI?

A

Graphical user interface

181
Q

man

A

Brings up the manual in the terminal

182
Q

cat

A

Print contents of a file in the terminal

183
Q

ls

A

List contents of a directory/file in the terminal

184
Q

pwd

A

Shows your working directory in the terminal

185
Q

echo

A

Add content to a file

186
Q

touch

A

Creates a new file

187
Q

mkdir

A

Creates a new directory

188
Q

mv

A

Rename a directory

189
Q

rm

A

Remove a file

190
Q

cp

A

Copy a file

191
Q

What are the three virtues of a great programmer?

A

Laziness, patience, hubris

192
Q

What is Node.js?

A

As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications.

193
Q

What can Node.js be used for?

A

back end services

194
Q

What is a REPL?

A

Read-eval-print-loop; used for single line commands in the terminal

195
Q

When was Node.js created?

A

2009

196
Q

What back end languages have you heard of?

A

Node.js, PHP

197
Q

What is a computer process?

A

An instance of a computer program being executed on one or more threads

198
Q

Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?

A

120

199
Q

Why should a full stack Web developer know that computer processes exist?

A

It’s important to know what processes are running at any given time so you can work with them

200
Q

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

A

The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require().

201
Q

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

A

process

202
Q

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

A

array

203
Q

What is a JavaScript module?

A

A single .js file

204
Q

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

A

__dirname, __filename, exports, module, require

205
Q

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

A

global, process

206
Q

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

A

To transfer information between JavaScript files

207
Q

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

A

Assign whatever you want to be exported to module.export; Then use require(“./fileName”) in the file where you want to import that information

208
Q

What is the JavaScript Event Loop?

A

The interaction between the call stack and the callback queue, which checks if the queue is empty or not, and if something is in the queue, it gets pushed to the call stack

209
Q

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

A

Blocking refers to code that is running, which blocks other code from being executed on the webpage until that stack is finished

210
Q

What is a directory?

A

A file system for storing data on your computer

211
Q

What is a relative file path?

A

A location that is relative to the current directory

212
Q

What is an absolute file path?

A

The complete location of the file, including which drive it was on

213
Q

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

A

fs

214
Q

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

A

writeFile

215
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

216
Q

What is a client?

A

A piece of computer hardware or software that interacts with a server.

217
Q

What is a server?

A

A piece of computer hardware or software that provides functionality for clients.

218
Q

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

A

GET

219
Q

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

A

An HTTP method, request target, and the HTTP version

220
Q

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

A

The protocol version, a status code, a status text

221
Q

What are HTTP headers?

A

HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value.

222
Q

Is a body required for a valid HTTP message?

A

No

223
Q

What is AJAX?

A

Ajax allows you to update parts of the DOM of an HTML page instead without the need for a full page refresh. Ajax also lets you work asynchronously, meaning your code continues to run while the targeted part of your web page is trying to reload (compared to synchronously, which blocks your code from running until that part of your page is done reloading).

224
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

225
Q

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

A

XMLHttpRequest

226
Q

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

A

load

227
Q

What is NPM?

A

A software registry that allows users to share and borrow packages

228
Q

What is a package?

A

Reusable code from other users that uploaded them to the npm website

229
Q

How can you create a package.json with npm?

A

You navigate to the directory and then run

npm init –yes

230
Q

What is a dependency and how to you add one to a package?

A

The packages installed by the user and required for the project

npm install package name

231
Q

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

A

The package is added to a node_modules folder

232
Q

How do you add express to your package dependencies?

A

npm install express

233
Q

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

A

listen()

234
Q

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

A

application/json

235
Q

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

A

It indicates the desired action for the server to take

236
Q

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

A

It parses incoming requests with JSON payloads; Whenever you use a post request, since you are sending data to the server

237
Q

What is Array.prototype.filter useful for?

A

It is useful for creating a new array when you only want to grab specific values from an existing array that meet a specific condition

238
Q

What is Array.prototype.map useful for?

A

when you want to run a function on every index in the array and return the same amount of values as the input array

239
Q

What is Array.prototype.reduce useful for?

A

When you want to run a function on every index in the array and return a single value

240
Q

What is “syntactic sugar”?

A

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

241
Q

What is the typeof an ES6 class?

A

Function

242
Q

Describe ES6 class syntax.

A

You define a class, and inside that class you define a constructor function where you pass the parameters you’re expecting, and then you can define multiple methods that you would want to run on that class

243
Q

What is “refactoring”?

A

Rewriting code to make it more readable, while still maintaining the same functionality

244
Q

What is Webpack?

A

A module bundler

245
Q

How do you add a devDependency to a package?

A

npm install –save-dev

246
Q

What is an NPM script?

A

an npm command that you define, that when called runs whatever you assigned to the script

247
Q

How do you execute Webpack with npm run?

A

npm run scriptName

248
Q

How are ES Modules different from CommonJS modules?

A

Their syntax is even more compact than CommonJS’s.

Their structure can be statically analyzed (for static checking, optimization, etc.).

Their support for cyclic dependencies is better than CommonJS’s.

249
Q

What kind of modules can Webpack support?

A

ES, CommonJS, AMD

250
Q

What is React?

A

React is a declarative, efficient, and flexible JavaScript library for building user interfaces.

251
Q

What is a React element?

A

Plain objects you create where you specific the element and value, that can be rendered into the DOM

252
Q

How do you mount a React element to the DOM?

A

ReactDOM.render(element, container[, callback])

253
Q

What is Babel?

A

babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. It also converts JSX

254
Q

What is a Plug-in?

A

a software component that adds a specific feature to an existing computer program.

255
Q

What is a Webpack loader?

A

loaders allow you to specify which files you want a specific dependency to run on before webpack compiles your files

256
Q

How can you make Babel and Webpack work together?

A

You configure webpack to specify which files you want Babel to transpile before webpack compiles all your files

257
Q

What is JSX?

A

A nice and readable way of creating elements in React

258
Q

Why must the React object be imported when authoring JSX in a module?

A

You need to import react and react-dom in order to create DOM elements in React

259
Q

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A

Using a babel-loader along with a babel plugin to convert JSX

260
Q

What is a React component?

A

Pieces of reusable code

261
Q

How do you define a function component in React?

A
defining a function or a class; function Welcome() {
  return <h1>Hello</h1>;
};
class Welcome extends React.Component {
  render() {
    return <h1>Hello</h1>;
  }
}
262
Q

How do you mount a component to the DOM?

A

ReactDOM.render(
,
document.getElementById(‘root’)
);

263
Q

What are props in React?

A

objects which are used to pass data between components

264
Q

How do you pass props to a component?

A

props as a parameter in your function/class

265
Q

How do you write JavaScript expressions in JSX?

A

in curly braces

266
Q

How do you create “class” component in React?

A

class ClassName extends React.Component

267
Q

How do you access props in a class component?

A

this

268
Q

What is the purpose of state in React?

A

to control what you want the user to see on the webpage

269
Q

How to you pass an event handler to a React element?

A

onClick attribute or different event attributes

270
Q

What Array method is commonly used to create a list of React elements?

A

map

271
Q

What is the best value to use as a “key” prop when rendering lists?

A

Ids or a unique string

272
Q

What are controlled components?

A

An input form element whose value is controlled by state

273
Q

What two props must you pass to an input for it to be “controlled”?

A

handle submit & handle change

274
Q

What does express.static() return?

A

a function

275
Q

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

A

the directory name of the current module

276
Q

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

A

It combines all its arguments to make a path

277
Q

What does fetch() return?

A

a promise

278
Q

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

A

get

279
Q

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

A

you define the desired method inside of the init object within your fetch call

280
Q

When does React call a component’s componentDidMount method?

A

After a component was rendered

281
Q

Name three React.Component lifecycle methods.

A

componentWillUnmount componentDidUpdate, componentDidMount

282
Q

How do you pass data to a child component?

A

props

283
Q

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

A

another function

284
Q
What does this code do?
const wrap = value => () => value;
A

A function that returns another function which returns the parameter from the 1st function

285
Q

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

A

closures