JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to represent/store numbers and other kinds of 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

first you declare a keyword (const, let, var) then you give the variable a 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

you assign a variable a value by declaring it, then using an “=” (assignment operator) followed by the value you want to store

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
$
_ (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

if two words are spelled the same, but the cases are different, they will represent different variables

ex var Hello and var hello would be 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

to represent text content (letters and other characters). Must be inside quotations

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

to represent quantities and other calculations involving numeric data

represent numeric 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 represent “true” or “false” (ie on and off).

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

it is the assignment operator

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

declaring the variable name and using the assignment operator to assign it a new value
ex hello = “hello” reassigns the variable hello to “hello”

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 intentional assignment, you must assign a variable to “null” to display no value

undefined is when a variable is assigned no value, i.e. no assignment operator was used.

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 keep track of what variable is being logged and when.

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

combining strings together to create a new string

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

serves as addition and/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 the variable (called on the left of the operator) to the value on the right of the operator and then assigns the called variable to the result of that expression.

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

What are objects used for?

A

serves as a grouping mechanism for other data types

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

What are object properties?

A

variables inside of an object

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

Describe object literal notation.

A

assigning an object to a variable name
declaring an object with curly braces

ex

var object = {
                    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 followed by the object name and property name you want to delete (can use dot or bracket notation).

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

use dot or bracket notation to find the object and property you want and then assign it to a new value.

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

What are arrays used for?

A

storing a list of values that are related to each other in an ordered fashion

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

Describe array literal notation.

A
brackets assigned to a new variable declaration
var arr = [];
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 objects, but they have “order”. their index number dictates their property order

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

tells you how many items are 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

objects that can carry out tasks that can also be reused.

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

name of function (optional)

function parameter list with optional parameters

opening curly brace

function code block

return statement (optional)

closing curly brace

ex function func(param) {
code
return statement
}

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 function followed by the parameter list (parentheses)

insert parameters inside parenthesis if function needs parameters

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

function definition has the keyword “function” before the name, and has parameters that act as placeholders within the parenthesis. Then it has the code block that will be executed when the function is called.

function call is just the name followed by parenthesis 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

a parameter is a placeholder for values to be input into the function

an argument is the actual value that will be placed

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

Why are function parameters useful?

A

it allows us to get different results from a function when provided with different values.

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

produces a value for the function

prevents any more code in the functions code block 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

it allows us to debug our code.

allows us to see the output of our code so we know if something is working as intended.

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

What is a method?

A

it is a function that is a property of an object

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

How is a method different from any other function?

A

you cannot call the method on its own, it needs to be called by 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

call the “.pop()” method by the object.

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

use the .floor() property on the Math object

ex Math.floor() and pass the number you want rounded down as an argument.

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

call the .random() property on 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

use the .splice() method on the array.

first argument is the position you want to target

second argument is the number of elements you want to delete

Any argument after is the data you want to insert into that position.

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 to add to the end of an array

.unshift() method to add to the front of the array

.splice() method to add in the middle of an array.

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

use the .split() method

first parameter is the “pattern” you want to split the string up by

second parameter is the max number if substrings you want returned

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, you need to store the return into a new variable
you can console log the variable that held the original string

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

~40

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

booleans (true or false)

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 check if a condition runs true before executing a code

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
if keyword
condition within parentheses
opening curly brace
code to be executed
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)
! (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

you can either use the && or || 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

being able to repeat a block of code under certain conditions

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

acts as a counter to let the loop know when to stop

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

it is the number of times that a function has repeated

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

condition is evaluated BEFORE executing the statement

before iteration

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

initialization expression is evaluated once BEFORE the loop begins

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

before the code statement is ran

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

at the end of the loop iteration and before the condition expression

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 the operand by one

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 (let x in object)

x represents the keys in the object

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

What is a “model”?

A

the structure of the webpage that it was given.

like a replica of the original thing

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

the html page

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

it refers to the “object’ data type in javascript that makes up the DOM tree

objects are what make up the model

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

What is a DOM Tree?

A

a parent element and its “branches” of children and their children

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.querySelector()

getElementById()

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

so you can reuse the selector

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

console.dir()

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 the page can load first before the script is run. if the script is run before the page, it will select nothing.

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

it takes a selector (in quotes ie a string) and returns the first element that matches the selector

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

it takes a selector (in quotes) and returns a node list of the document’s elements that match the selector

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

What is the purpose of events and event handling?

A

to make the browser respond to user interactions. it makes the the page feel more interactive

events are what the user does and the event handling is what the page does in response to the user events

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

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

A

no

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

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

A

the ‘event’ object

it is an object that returns all the relevant information that happened on that event in a object format

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

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

A

a property of the Event object. It returns the element where the event occurred.
you can check MDN. search up event.target mdn.

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

What is the difference between these two snippets of code?

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

A

no parenthesis is you are calling the method
parenthesis means you are calling the result of the method. It would tell the page that the function will run once the page is loaded, instead of when it is called.

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

What is the className property of element objects?

A

it is a property that allows us to get the class names of an element and set the values

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

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

A

document.querySelector(‘select element).className = ‘class name’

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

What is the textContent property of element objects?

A

property that represents the text content of the selected node and its descendents.

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

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

A

document.querySelector(‘select element’).textContent = ‘desired text’

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

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

A

no

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

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

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

A

it makes it easier to access with JavaScript

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

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

(ie their cursor is blinking)

A

‘focus’ is fired when a user clicks on a form

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

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

A

‘blur’ is fired when a user clicks outside an input area

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

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

A

‘input’ is fired when a user starts typing

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

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

A

the ‘submit’ event is fired

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

What does the event.preventDefault() method do?

A

it prevents the default action of something from occurring.

ie submit wont refresh the page
checking a checkbox won’t fill in a check

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

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

A

it refreshes the page

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

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

A

the ‘.element’ property

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

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

A

the ‘.value’ property

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

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

A

having to rewrite your entire code if something early on was non-functional

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

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

A

being able to see what is happening in real time so you can debug easier.

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

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

A

no, it stores it into a variable to be added later with .appendChild()

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

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

A

use .appendChild()
attach .appendChild() to the element you want to add to, and insert the actual child into the parenthesis of .appendChild().

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

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

A

the name of the attribute you want to set, then the value you want to assign the attribute.

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

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

A
select the parent element you want to target via querySelector()
    -create the actual element you want to add (ex li, div, ul etc) and store into variable
    -var newElement = document query + .createNewElement()
append some text content to previously mentioned variable (optional)
    -var newText = document query + .createTextNode(‘string’)
newElement.appendChild(newText)
append the final variable to the element you want to add to
    -Parent.appendChild(newElement)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
107
Q

What is the textContent property of an element object for?

A

it is used for getting all text content within a node and its descendants or to set the value for a node and its descendants

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

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

A

.setAttribute(‘class’, ‘classname’)

query.className = ‘classname’

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

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

A

functions are easier to test, you only need to output one thing in a function vs 20 in a for loop
makes repeating an action easier

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

What is the event.target?

A

the element that triggered the event. the most “specific” element that was triggered

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

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

A

because of event flow

default is “bubbling” it selects the most specific (deepest child) element that is within the targeted event

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

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

A

event.tagName gets the element in all caps

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

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

A

it takes a string of selectors.
it returns the closest ancestor of the selected element that matched the selector argument that was passed

returns the actual element

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

How can you remove an element from the DOM?

A

use .remove() after the selected element you queried for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
115
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
that parent is then able to listen to any events that happen within it
you can then use methods like tagname or matches() to target more specific events within that parent

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

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

A

takes a string of a css selector
returns a boolean (true or false the element has the selector)

Ex document.querySelector(“li”).matches(“endangered”). If an element of li has a class of “endangered”, the method will return true

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

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

A

.getAttribute() attached to the targeted element

The argument will be a string value of the name of the attribute value you want
Ie “data-view” will return the value of “data-view”

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

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

A

after every step

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

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

A

you would have to add another event listener for each specific tab

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

several if else statements
if event target matched one condition, you set that one to a certain class name
then you set the other two targets to different class names
create as many if statements as there are targets

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

What is a breakpoint in responsive Web design?

A

the point at which a media query is introduced when a style is being deployed.

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

What is JSON?

A

JavaScript Object Notation
a string that has a format that resembles javascript objects.’
it contains only properties, no methods
it is a way to serialize data into a string and be able to transfer data more efficiently.

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

What are serialization and deserialization?

A

serialization
a way of turning an object into basic memory (eg bytes) so you can transfer the data easier

deserialization
reverse of serialization. Turns a stream of bytes into an object in memory

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

Why are serialization and deserialization useful?

A

they allow us convert something and store it in a certain way so we can transfer/store it

deserialization allows us to take stored thing and ‘unpack’ it to its original form

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

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

A

you can use JSON.stringify to turn it into a JSON string

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

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

A

JSON.parse to unpack the string.

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

How do you store data in localStorage?

A

use the .setItem() method and pass in the key and value pair you want to store

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

How do you retrieve data from localStorage?

A

you can use the .getItem() method and pass the key you want as a string.

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

What data type can localStorage save in the browser?

A

strings

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

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

A

when the document is about to be ‘unloaded’ meaning before all data is cleared

ie before the data is ‘cleared’

before user leaves the page.

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

What is a method?

A

a function that is a property of an object

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

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

A

definition: the name of the method is a key and the actual function is the value inside an object, and that object is being assigned to a variable
call: the method is attached to an object via dot property

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

Describe method definition syntax (structure).

A

create an object with curly braces
name of the method (ie name of function) is the key
the value is a function keyword, followed by the opening curly brace for code block, then the code block itself.
the object you created is then assigned to a variable name.

134
Q

Describe method call syntax (structure).

A

name of object, followed by dot name of method ()

object.method();

135
Q

How is a method different from any other function?

A

methods can only be used by certain objects and must be attached to objects.
functions can be called whenever

136
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (variables, properties) and behavior (methods)

137
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

138
Q

What is “abstraction”?

A

working with complex things in a simple way

ie generalizing something so that you know what it does, without having to know how its done

139
Q

What does API stand for?

A

application programming interface

140
Q

What is the purpose of an API?

A

to give programmers a way to interact with a system in a simplified manner (ie abstraction)
ie APIs hide the internal details of how a system works, and instead only lets the programmer know what it does.

a connection between programs and programmers.

141
Q

What is this in JavaScript?

A

an implicit parameter of all JavaScript functions

it is a variable that holds the object that the behavior is currently being executed within.

‘this’ is a parameter that takes the object to the left of the method call as its argument.

142
Q

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

A

call time

143
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 method isn’t being invoked, so ‘this’ isn’t assigned any value

144
Q
"var character = {
 	 firstName: 'Mario',
  	greet: function () {
    	var message = 'It\'s-a-me, ' + this.firstName + '!';
   	 console.log(message);
  	}
};"

Given the above character object, what is the result of the following code snippet? Why?

“character.greet()”

A

It’s-a-me, Mario!

the ‘owner’ of the greet function is ‘character’. so when this.firstName is being called, it is saying the firstName property of the owner of ‘this’ function

145
Q
"var character = {
 	 firstName: 'Mario',
  	greet: function () {
    	var message = 'It\'s-a-me, ' + this.firstName + '!';
   	 console.log(message);
  	}
};"

Given the above character object, what is the result of the following code snippet? Why?

"var hello = character.greet;
hello();"
A

It’s-a-me, undefined

the greet method is not being invoked, so ‘this’ doesn’t get a value. hello is just being assigned the value of greet, which is the function inside of it, not the actual value it would return because it is not being invoked.

when hello is being called, it is being called by the window object, so ‘this’ would be the window object if ‘this’ was called.

146
Q

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

A

‘this’ is nothing until the function or method is being called.

147
Q

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

A

the object to the left of the dot. Whatever is calling the method/function is ‘this’
else it is the window object

148
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (prototypal)

149
Q

What is a prototype in JavaScript?

A

a kind of mechanism that allows other javascript objects to inherit features (ie methods, properties) from one another

an object that contains properties and methods that can be used by other objects

150
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

These methods are defined on a ‘prototype’ object which are then borrowed from the prototype and used when called.

151
Q

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

A

in the prototype object

152
Q

What does the new operator do?

A

lets users create a user-defined object type or a built in object type that has a constructor function.

ie using new creates a brand new object that has a template of key-values. The new object is then assigned to a variable name.

153
Q

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

A

prototype

154
Q

What does the instanceof operator do?

A

checks to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. returns boolean
checks to see if an object was made by a constructor

155
Q

What is a “callback” function?

A

a function passed into another function as an argument.

156
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

157
Q

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

A

setInterval() function

158
Q

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

A

0

159
Q

What do setTimeout() and setInterval() return?

A

timeoutId and intervalId respectively. They are non-zero value identifiers created by the call functions that allow you to target specifically those timeouts/intervals so you can stop them.

160
Q

What is a client?

A

a piece of computer hardware or software that accesses a service made available by a server

161
Q

What is a server?

A

a piece of computer hardware or software that provides functionality to clients.

162
Q

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

A

GET request

163
Q

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

A
HTTP method (a word that describes the action to be performed)
request target (URL)
HTTP version (defines structure of the remaining message)
164
Q

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

A

protocol version
status code
status text

165
Q

What are HTTP headers?

A

additional information passed between clients and servers within an HTTP request or response. (a case sensitive string followed by a colon)

166
Q

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

A

MDN

167
Q

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

A

no

168
Q

What is AJAX?

A

a way of building complex and dynamic webpages using XMLHttpRequests.
users can do things in a web browser while waiting for data to load

169
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

170
Q

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

A

XMLHttpRequest

171
Q

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

A

the ‘onload’ event

172
Q

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

A

prototypal inheritance.

173
Q

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

A

a series of statements to be performed. functions, conditionals, loop

174
Q

What does block scope mean?

A

code within curly braces {}

175
Q

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

A

both are block scope

176
Q

What is the difference between let and const?Why is it possible to .push() a new value into a const variable that points to an Array?

A

const is a ready-only reference. You can update the value of the reference, but not the reference itself.

let allows you to reassign/update its value

177
Q

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

A

const creates a read-only reference value. the reference cannot be changed, but the value of the reference can. You can create a reference, but once it is created, you cannot change that reference.

178
Q

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

A

whether you will have to reassign the variable.

179
Q

What is the syntax for writing a template literal?

A

using backticks `` with placeholders (${})

placeholders will be JS expressions or values that can be inserted into the template literal

180
Q

What is “string interpolation”?

A

being able to substitute part of a string with values or expressions (ie variables)

181
Q

What is destructuring, conceptually?

A

assigning a value into a variable

182
Q

What is the syntax for Object destructuring?

A

const {objectProperty: newPropertyName (only need new name if there is going to be clashing variable names)} = objectName

183
Q

What is the syntax for Array destructuring?

A

const [ arrayElementName, arrayElementName, …] = arrayName

184
Q

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

A

object destructuring uses {}, array destructuring uses []. destructuring, the braces/brackets go on the left of the assignment operator, creating goes on the right.

185
Q

What is the syntax for defining an arrow function?

A

let funcName = (param1, param2) => {return statement}

186
Q

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

A

arrow functions become unable to evaluate statements without curly braces. Can only evaluate expressions
with curly braces, you need return key because it is a statement, without curly braces you don’t need a return key because it is then an expression only.

187
Q

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

A

because arrow functions don’t have a ‘this’ value, it looks for the first definition of ‘this’ it encounters.

no ‘this’ value in a function it defaults to the window object.

this is determined during function definition, not call

188
Q

What is a CLI?

A

Command Line Interface

allows user to interact with computer to processes commands in the command line

189
Q

What is a GUI?

A

form of user interface that allows users to interact with electronic devices through graphical icons and audio indicators.

aimed towards consumers of technology and not producers

190
Q

give an example of the command ‘man’

A

man - when you want to see the manual(man man to see the manual for the manual) man cat shows you the manual for the ‘cat’ command

191
Q

give an example of the command ‘cat’

A

cat - when you want to see the manual for the ‘cat’ command (concatenate files and print on the standard output) man cat to see manual on ‘cat’. prints out the text content of a file, can be used to combine files

192
Q

give an example of the command ‘ls’

A

list directory contents. ls -a displays all the contents in a directory, even those starting with a dot (.)

193
Q

give an example of the command ‘pwd’

A

prints the current directory. pwd > new-filename.txt creates a new file with the current directory

194
Q

give an example of the command ‘echo’

A

displays a line of text. echo “hello world” prints out hello world into the console. typing a string and then using an arrow (>) followed by a filename will write that string into that new file.

195
Q

give an example of the command ‘touch’

A

changes file timestamps. Creates a new file if the file does not exist (unless specifically told not to). touch filename.txt creates a new file within the current directory

196
Q

give an example of the command ‘mkdir’

A

makes directories. you can make nested directories by using ‘/’ between directory names (each directory name is a nested forward slash)

197
Q

give an example of the command ‘mv’

A

move/rename files (move source to destination OR move source to directory) mv SOURCENAME DESTINATIONNAME

198
Q

give an example of the command ‘rm’

A

removes files/directories. rm -r DIRECTORYNAME will remove directories and all of its contents. rm FILENAME will remove the file from the current directory

199
Q

give an example of the command ‘cp’

A

copy files and directories from a source to a destination. cp SOURCE DESTINATION. cp -r copies directories recursively. this means that it will copy subdirectories and their contents. without -r it skips the directories.

200
Q

What are the three virtues of a great programmer?

A

Laziness
Impatience
Hubris

201
Q

What is Node.js?

A

a program that allows JavaScript to be run outside of a web browser.

202
Q

What can Node.js be used for?

A

build back ends for web applications, command line programs, any kind of automation that developers wish to perform

203
Q

What is a REPL?

A

Read-eval-print loop

a computer programming environment that takes user inputs and executes them and returns a result.

204
Q

When was Node.js created?

A

2009

205
Q

What back end languages have you heard of?

A
javascript
python
ruby
java
typescript
206
Q

What is a computer process?

A

the instance of a computer program that is being executed by one or many threads. Contains the program code and its activity. The execution of instructions stored in a file on a disk

207
Q

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

A

full stack works by making multiple processes work together, so understanding how things interact is necessary so you know when things need to be running.

208
Q

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

A

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

209
Q

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

A
because ‘process’ is a global object, it can be accessed by simply calling ‘process’
const process = require(‘process’)
210
Q

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

A

an array of strings

first element is the process.execPath
second element is the path of the JS file
each following element is any additional arguments passed into the command line

211
Q

What is a JavaScript module?

A

a chunk of JavaScript code that has functionality that is in its one file.

212
Q

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

A
module
require
exports
\_\_filename
\_\_dirname
213
Q

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

A
clearImmediate(immediateObject)
clearInterval(intervalObject)
clearTimeout(timeoutObject)
console
global
process
214
Q

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

A

to export a value/function from one file to another

allow other files to use the module’s functionality.

215
Q

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

A

by using the require function and passing the relative url to the file you want to import as an argument.

216
Q

What is the JavaScript Event Loop?

A

brings async functions back into the flow of the stack
responsible for the stack and queue
controls when asynchronous events come back into the stack. Event loop will wait until the stack is cleared, and then execute whatever is in the queue.

217
Q

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

A

blocking is synchronous ie each event waits for the previous one to finish before getting executed

non-blocking is asynchronous ie functions are called in order and do not have to wait for the previous function to finish executing

218
Q

What is a directory?

A

a folder(container) that holds other files (references to other files)

219
Q

What is a relative file path?

A

a file path that is ‘relative’ to the path of the current location. ie the program assumes the path of the current location plus whatever the relative path is.

220
Q

What is an absolute file path?

A

the entire file path to get into the file that is desired

221
Q

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

A

fs module

222
Q

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

A

.writeFile

223
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous, but there are synchronous options.

224
Q

What is a client?

A

a service requester

225
Q

What is a server?

A

providers of service

226
Q

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

A

GET requests

227
Q

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

A

the ‘Start line’ which contains
an HTTP method (GET, PUT, POST)
the request target (the url)
http version

228
Q

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

A

the start line (status line)
protocol version
status code (indicates success or failure)
status text (explanation of the status code so humans can understand it)

229
Q

What are HTTP headers?

A

a case sensitive string followed by a request. Specifies the request or describes the body included in the message.
ie modifies the requests, ie formatting, language, encoding.
additional information passed with an HTTP request or response.

230
Q

Is a body required for a valid HTTP message?

A

no, not all requests have them.

231
Q

What is NPM?

A

a library of a bunch of packages/modules that users can use or share with other users

library that holds packages(modules) from other users

232
Q

What is a package?

A

bits of reusable code (packages or modules)

a directory with one or more files of reusable code

233
Q

How can you create a package.json with npm?

A

navigate to your package location

npm init –yes

package.json is a json file that holds all the packages that were used in your program.

234
Q

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

A

a piece of code/package from a library that is needed/used by your code to run

run ‘npm install name-of-package’ in a package directory

235
Q

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

A

it gets added to the package.json dependencies object as a property. added to node_modules folder
package is downloaded from the registry
it is now usable in your code.

236
Q

How do you add express to your package dependencies?

A

npm install express –save

237
Q

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

A

.listen() method

238
Q

How do you mount a middleware with an Express application?

A

with the .use() method

239
Q

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

A

request object and response object

240
Q

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

A

application/json; charset=utf-8

241
Q

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

A

takes incoming requests and parses them into a JSON string. Returns middleware that only parses JSON.
When you want to take an input from the command line and convert it into JSON format

242
Q

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

A

it lets the server know what action to perform based on the request method. describes intent of client. communication tool between server and client.

243
Q

What is PostgreSQL and what are some alternative relational databases?

A

relational database system. (data organized into tables of columns and rows with unique keys identifying each row)
Other databases: MySQL, SQL Server, Oracle

244
Q

What are some advantages of learning a relational database?

A

storing data that relates to other pieces of data in an organized way.
stores data in a way that makes it harder to corrupt and easier to keep the integrity of the data.
most apps use relational databases

245
Q

What is one way to see if PostgreSQL is running?

A

sudo service postgresql status

top command

246
Q

What is a database schema?

A

a collection of tables. It defines how the data in a relational database should be organized

247
Q

What is a table?

A

a list of rows with the same set of attributes

248
Q

What is a row?

A

a set of attributes. a list that holds columns(attributes) with the same kind of values. attributes being descriptions of the kind of data that is being held,

249
Q

What is SQL and how is it different from languages like JavaScript?

A

a way of interaction with relational databases

sql is a declarative programming language, meaning you give the program a set of rules that describe what you want it to do, then the program will try its best to interpret what you want. database engine figures out how to deal with instructions you give

js is an imperative language. you explicitly tell the program what you want

250
Q

How do you retrieve specific columns from a database table?

A

the select statement followed by the name of the column(s) you want in double quotes.
the you use the from statement to state which table you want to pull the data from

251
Q

How do you filter rows based on some specific criteria?

A

use the where statement to define conditions.

252
Q

What are the benefits of formatting your SQL?

A

get specific results and only the results you want. Databases can be huge, and getting all that information can be useless if you can’t read it
its easier to read

253
Q

What are four comparison operators that can be used in a where clause?

A

=, “>” ,”< “, !=

254
Q

How do you limit the number of rows returned in a result set?

A

limit statement followed by the number of lines you want

255
Q

How do you retrieve all columns from a database table?

A

select *

256
Q

How do you control the sort order of a result set?

A

order by “column-name” desc or asc order (default is ascending so it can be omitted if thats what you want)

257
Q

How do you add a row to a SQL table?

A

insert into “table name” (“column name”, “column name”, …)
values (‘value for column one’, ‘value for column 2’)
make note of single and double quotes

258
Q

What is a tuple?

A

a list of values in a specified order

259
Q

How do you add multiple rows to a SQL table at once?

A

after values, include as many tuples with the correct number of values within the tuple
ie values (‘data’, ‘data’, ‘data’)
(‘data2’, ‘data2’, ‘data2’)

260
Q

How do you get back the row being inserted into a table without a separate select statement?

A

returning clause

261
Q

How do you update rows in a database table?

A

update statement followed by the name of the table

then the set clause followed by the name of the column and then the value

then a where clause to specify which one to update.

update “products”
set “price” = 100.

262
Q

Why is it important to include a where clause in your update statements?

A

it will update every row that has the targeted column name, unless you specify what row to update.

263
Q

How do you delete rows from a database table?

A

delete from statement followed by name of table
then a where clause to specify which thing to delete
WARNING if a where statement is omitted, then the whole table will be deleted. this action cannot be undone.

264
Q

How do you accidentally delete all rows from a table?

A

omit a “where” statement

265
Q

What is a foreign key?

A

an identifier that allows you to refer to specific rows in another table.

266
Q

How do you join two SQL tables?

A

select “name of data you want”
from “table name”
join “second table name” using (“name of foreign key column”);

267
Q

How do you temporarily rename columns or tables in a SQL statement?

A

use the keyword ‘as”
select “products”.”name” as “product”
this takes the name column of the products table and renames the ‘name’ column to ‘product’ when you join two tables.

268
Q

What are some examples of aggregate functions?

A

max()
avg()
array_agg()
count()

269
Q

What is the purpose of a group by clause?

A

to return a value based off of an entire group.

270
Q

What are the three states a Promise can be in?

A

Pending: initial state, neither fulfilled or rejected
Fulfilled: operation was successful
Rejected: operation failed

271
Q

How do you handle the fulfillment of a Promise?

A

use the “then()” method and pass a callback as the first argument for what to do when the promise is fulfilled

272
Q

How do you handle the rejection of a Promise?

A

use the “then()” method and pass a callback as the second argument for what to do when the promise is rejected.
you can also use a catch() method which ‘catches’ any failures and performs whatever callback function is called when a promise fails
use console.error (error.message) to console log a custom error message when a promises is rejected.

273
Q

What is Array.prototype.filter useful for?

A

creating a new array by picking out elements from another array that pass the function requirements.

274
Q

What is Array.prototype.map useful for?

A

performing a function on each array element and adding the return to a new array.

275
Q

What is Array.prototype.reduce useful for?

A

combining elements of an array into a single value.

276
Q

What is “syntactic sugar”?

A

language that is designed to look nicer and easier to read

277
Q

What is the typeof an ES6 class?

A

function.

278
Q

Describe ES6 class syntax.

A
class keyword followed by name of class in with capital letter
class Person {}
call the constructor function with an argument of what you want 
constructor(name) {}
within constructor function assign argument to this.argumentName (eg this.height =height)
close the constructor function
define the method you want to assign to the class
getName() {}
within the method, return the this statement.
Ex class Rectangle (
  constructor(height, width) {
  this.height =height
  this.width = width
}
)
279
Q

What is “refactoring”?

A

restructuring code without changing the behavior. Intended to improve design (similar to syntactic sugar)

280
Q

What is Webpack?

A

a tool that lets you bundle your JavaScript modules. Handles modules and resources and assets at the same time.
it is a module bundler.
allows you to handle modules within node and npm.
a way that makes sure your modules work with whatever stack you are using.

281
Q

How do you add a devDependency to a package?

A

after install you add –save-dev

282
Q

What is an NPM script?

A

a script of code that npm will run when npm run is initiated

commands you can make npm do

283
Q

How do you execute Webpack with npm run?

A

npm run followed by the name of the property whose value is assigned as “webpack”

284
Q

How are ES Modules different from CommonJS modules?

A

instead of require() and module.export, ES modules use declarative syntax (eg import, export)
ES6 modules are a part of the JavaScript language, CommonJS is not.

They are both ways to package js modules

285
Q

What kind of modules can Webpack support?

A
ECMAScript
CommonJS
AMD
Assets
WebAssembly
286
Q

What is React?

A

a declarative JavaScript library for building UI

287
Q

What is a React element?

A

a lightweight description of what to render. An object.

a plain object describing a component instance or DOM node and its desired properties

288
Q

How do you mount a React element to the DOM?

A

ReactDOM.render()

289
Q

What is Babel?

A

a toolchain that converts ES 2015+ into backwards compatible versions of JS in older browsers
a JS compiler

290
Q

What is a Plug-in?

A

software component that adds a specific feature to an existing program

291
Q

What is a Webpack loader?

A

loaders transform a modules source code and turn them into JavaScript.

292
Q

How can you make Babel and Webpack work together?

A

install babel-loader as a devdependency

293
Q

What is JSX?

A

a syntax extension of JavaScript. Lets you describe what a UI should look like. Allows you to combine logic and markup into one file

294
Q

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

A

JSX makes calls to the react object. JSX translates the input into react language and then calls the react object.

295
Q

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

A

connecting them with babel loader, then adding the jsx transform into bable
install the @babel/plugin-transform-react-jsx as a devdependency

296
Q

What is a React component?

A

similar to JS functions, they take in input and return a React element.

297
Q

How do you define a function component in React?

A
similar to JS function definition
function keyword, name of function with a capital letter, parameters
inside code block return the JSX element you want React to display.
ex function Welcome(props) {
	return <h1> Hello, {props.name}</h1>
}
298
Q

How do you mount a component to the DOM?

A

angle brackets, with the name of the component along with any props
ie const element =
the Welcome component is called with the prop.name set to Sara
props is an object that holds all the key value pairs that are inserted after the component.

299
Q

What are props in React?

A

props are object key value pairs that can be passed as arguments in JSX components.

300
Q

How do you pass props to a component?

A

you create an object and store the values inside that object.

301
Q

How do you write JavaScript expressions in JSX?

A

surround the expression within curly braces {}

302
Q

How do you create “class” component in React?’

A

class keyword followed by the name of the class and then you extend the React.Component. Followed by opening code block with a render method definition and then a return statement with the React element you want to display.

303
Q

How do you access props in a class component?

A

this.props.name

304
Q

What is the purpose of state in React?

A

to let React know when a component has changed and therefore needs to re-rendered.
to keep track of values that change over time

305
Q

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

A

you pass the event attribute and assign it a JavaScript expression (within curly braces) that holds the name of the event handler (method without the parenthesis)
eventName = {eventFunction}

306
Q

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

A

map method

307
Q

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

A

a string that uniquely identifies that object.

308
Q

What are controlled components?

A

components that maintain their own state and update it based on user input
eg input, textarea, select

309
Q

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

A

onChange and value

310
Q

What does express.static() return?

A

returns a middleware function

all the files that are within the specified folder/filepath that was given as an argument

311
Q

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

A

gives you the directory of the current module

absolute path of the directory to current module

312
Q

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

A

joins all path segments into one

ie every argument passed will become a path segment that it creates

313
Q

What does fetch() return?

A

a promise that resolves with a Response object which represents the entire HTTP response (which has a JSON body content)

314
Q

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

A

GET

315
Q

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

A

within the second argument as an object

eg {method: ‘GET’}

316
Q

When does React call a component’s componentDidMount method?

A

immediately after a component is mounted (ie inserted into the tree)
after the render method
only happens one time after the first successful render

317
Q

Name three React.Component lifecycle methods.

A

constructor
render
componentDidMount
componentDidUpdate

318
Q

How do you pass data to a child component?

A

via constructor props.

319
Q

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

A

another function

320
Q

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

A

returns the anonymous function which then returns the value variable
When pass an argument into wrap and assign the return to a variable, then call that new variable with the new

321
Q

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

A

definition (every function)

322
Q

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

A

closures (the combination of a function and the lexical environment within that functions declaration)
the environment is any local variables that were ‘in-scope’ when the closure was created
when the function runs, it creates a reference to that lexical environment within the variable that it is stored in.

323
Q

What does the acronym LIFO mean?

A

Last In First Out

324
Q

What methods are available on a Stack data structure?

A

push, pop, peek, print

325
Q

What must you do to access the value at an arbitrary point in a stack (not just the “top”)?

A

keep popping the top of a stack off

326
Q

What does the acronym FIFO mean?

A

first in first out

327
Q

What methods are available on a Queue data structure?

A

enqueue, peek, dequeue, print

328
Q

What must you do to access the value at an arbitrary point in a queue (not just the “front”)?

A

dequeue from the front until you reach the arbitrary point

329
Q

How are linked lists different from an array?

A

linked lists are sequential access and not random (arrays are random) meaning that you always need to start from the beginning and go through each node to get to a specific node.

330
Q

How would you access an arbitrary node in a linked list (not just the “head”)?

A

jump through each node using ‘next’ until you are at the node you want.