Javascript Flashcards

1
Q

What are objects used for?

A

In JavaScript, an object is a standalone entity, with properties and type. An object is a collection of related data and/or functionality. Objects can be used for data models

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

What are object properties?

A

A property of an object can be explained as a variable that is attached to the object. The properties of an object define the characteristics of the object.

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

Describe object literal notation.

A

opening and closing curly brace

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

How do you remove a property from an object?

A

delete operator followed by object.property

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

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

A

bracket or dot notation: object.property or object[property]

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

What is the purpose of variables?

A

To store values to the variable so we can reuse it

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

How do you declare a variable?

A

var keyword variableName

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

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

A

= (assignment operator) valueOfVariable (on right of variable declaration)

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

What characters are allowed in variable names?

A

numbers, letters, $, period, underscore

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

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

A

Variable names must be cased consistently

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

What is the purpose of a string?

A

To be used with text

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

What is the purpose of a number?

A

To be used with calculations, to store numerical values

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

What is the purpose of a boolean?

A

On/off switch. To determine to run script or not. Useful when code has multiple paths

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

What does the = operator mean in JavaScript?

A

Assigment operator, assigns value to variable

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

How do you update the value of a variable?

A

variableName = newValue;

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

What is the difference between null and undefined?

A

Null- intentional absence of value by user

Undefined- value does not exist according to computer

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

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

A

Gives value context and indicates what that value is

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

What is string concatenation?

A

Joining strings end to end with + operator

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

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

A

Addition and concatenation

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

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

A

The += operator adds the value on its right to the variable or property on its left, and assigns the result to the variable or property on its left

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

What are arrays used for?

A

To store a collection of data

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

Describe array literal notation.

A

var variableName = [];

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

Objects contain properties related to the object and functions (methods).
Arrays are a collection of data

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

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

The length property of an object which is an instance of type Array, sets or returns the number of elements in that array

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

How do you calculate the last index of an array?

A

subtract 1 for the value returned from array.length

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

What is a function in JavaScript?

A

A set of statements that performs a task or calculates a value. Takes some input (arguments) and returns an output

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

Describe the parts of a function definition.

A

function keyword, optional function name, parameters, curly braces for code block, 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

functionName(arguments)

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

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

A

In a function call, the function is being executed and arguments are passed into the parameter field to return an output. In a function definition, no output is being generated and the function keyword is used to define the function and there is a code block of statements

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

Arguments are the values being passed into parameters. Parameters are like placeholders

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

Why are function parameters useful?

A

They let you know how many inputs are required and depending on the name, the context of the values that should be passed into 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

To end the function and to generate an output/result

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

Why do we log things to the console?

A

To check the output of our functions/methods

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 programmed procedure that is defined as part of a class and included in any object of that class. A function defined within 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 and function are both a set of instructions. A method is associated with an object while a function is not. Example: the push method is associated with array literals but not strings.

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

array.pop();

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

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

A

Math.floor();

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

How do you generate a random number?

A

Math.random()

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

How do you delete an element from an array?

A

array.splice(index of unwanted element, #of elements you want removed starting from that index)

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

array. push()

array. unshift()

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

string.split(delimiter/pattern you want the string split at);
ex: var str = “Crocodiles are super scary”
var array = str.split(“ “); //splits at every space
array = [Crocodiles, are, super, scary]

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 they do not change the original string. Strings are immutable, cannot be added onto or deleted. We can check by console logging 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. They’re useful when the situation has a need for it. Ex. In financial calculations dealing with dollars and cents, calling the math.floor() function would lead to a lot of inaccuracies

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

boolean data type

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

It is for decision-making for guiding the program to follow a certain path depending on whether a condition has been met or not

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, if the condition is not met, you will naturally be exited out of the if-statement

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 if (condition) {
code block
}
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 (returns true if all anded values are also true)
|| or (returns true if at lease one or-ed value is true)
! 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

put each expression in set of parenthesis

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

Loops allow you to repeat a process over and over without having to write the same (potentially long) instructions each time you want your program to perform a task

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

the condition of a loop marks a stopping point.

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

One iterations is one completed loop, one run-through of the code

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

In the beginning, before each 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

When the loop starts, before anything else. One time

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

Every time the loop runs. Before the code block inside the loop is executed. Before each time the loop iterates

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

Each time after the code block is executed. After each iteration of the loop, before the condition is checked

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

It increments the value of the variable by one. Reassigns, substitutes the value in place of the original value

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

For (var x in object) {code block}

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

To check for errors, to make sure our functions and code is returning the desired values

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

What is a “model”?

A

A model is called a DOM tree and it is stored in the browsers’ memory. Models are made of objects and nodes

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 HTML page

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

the datatype object

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

What is a DOM Tree?

A

The Document Object Model (DOM) is the data representation of the objects that comprise the structure and content of a document on the web. The DOM represents the document as nodes and objects; that way, programming languages can interact with the 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()

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

getElementsByClassName()

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

You might need to access an element more than once. It’s more efficient to store a value in a variable because the browser doesn’t need to look through the DOM tree to find the same element again

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

The browser needs to load all the HTML and CSS before the JavaScript code can access them

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

a css selector in between quotes. It 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

a css selector in between quotes. It returns all the element that have that match.

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

What is the purpose of events and event handling?

A

To trigger a particular function, for greater user interactivity with the web application

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

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

A

addEventListener

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

What is a callback function?

A

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

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

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

A

event object with all data about whatever occurred/describes the event

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

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

A

The element the event happened on.
The element node that is being checked for the occurrence of an event.
console log event.target

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

What is the difference between these two snippets of code?

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

A

When a function has no arguments, it does not receive any data from the calling function

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

What is the className property of element objects?

A

The className property of the Element interface gets and sets the value of the class attribute of the specified element

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

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

A

document.querySelector(‘name’)

elementNodeReference.className = ‘.class-name’;

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

What is the textContent property of element objects?

A

The textContent property of the Node interface represents all the text content of the node and its descendants.

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

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

A

query for element

elementNode.textContent = ‘text’;

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

No. Ex: call back function argument in addEventListener method

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

more complicated. Javascript functionality should be reliant on data stored in javascript

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

for later reuse, to reference back to the values stored in the variables. For efficiency

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

What does the transform property do?

A

The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.

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

Give four examples of CSS transform functions.

A

translateY, rotate, skew, scale

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

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

A

focus event

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

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

A

Blur event

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

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

A

input event

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

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

A

submit event

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

What does the event.preventDefault() method do?

A

The preventDefault() prevents the default action of an event

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

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

A

It makes the form values clear from the fields?

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

You have no idea at what point in the code things went wrong. You don’t know what the values are in essential variables.

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

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

A

You can see what is happening at any line of code. You can see whether your code is doing what it’s supposed to be doing each step of the way.

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 creates an element node in the dom tree. It creates a javascript object but it is not visible in the html page.

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

parentElement.appendChild(childElement);

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

setAttribute(‘attributeName’, ‘attributeValue’)

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

var someEl = document.createElement(‘element’);
var elText = document.createTextNode(‘text’);
someEl.appendChild(elText);
find the parent (querySelector(‘parentEl’);
parentEl. appendChild(someEl);

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

The textContent property of the Node interface represents the text content of the node and its descendants. It is useful when you only want to change the content of an already existing element. To get and set text content

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

className property, setAttribute() method

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

You can test the function easily and pass values into to see the output. Reuse the code easily.

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

What is a method

A

a special kind of property that has a function

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

The transition property is shorthand for which four CSS properties?

A

transition-delay - how long to wait to start transition
transition-duration - how long the animation time is
transition-property - sets the CSS properties to which a transition effect should be applied.
transition-timing-function - sets how intermediate values are calculated for CSS properties being affected by a transition effect (ease-in steps)

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 the event happened on

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- the order in which the events fire.

Event bubbling: the event starts at the most specific node and flows outwards to the least specific one

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

event.target.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 in the desire selector string. It finds the closest ancestor node that matches the selector string

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

How can you remove an element from the DOM?

A

elementNode.remove();

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

wrap the clickable element in a parent element. Put the listener on the parent element. Whenever the child is clicked, the listener on the parent will recognize that event. Event delegation

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

What is the event.target?

A

The element that triggered the event

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

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

A

Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist), removed from document flow. All descendant elements also have their display turned off.

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

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

A

The matches() method checks to see if the Element would be selected by the provided selectorString – in other words – checks if the element “is” the selector. The argument is the selector string. The return is a boolean

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

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

A

element.getAttribute(attributeName)

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

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

A

Every step

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

createElement(), add textContent, appendChild, className

you would have to addEventListener to each element

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

You would set a condition for every “view”. You’d get the view’s index and check if it was either ‘css’, ‘html’, or ‘javascript’ and change the classes if it happened to meet the specified value.

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

What is JSON?

A

JSON is a text-based data format following JavaScript object syntax
JavaScript object notation

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

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.

Deserialization is the reverse process: turning a stream of bytes into an object in memory.

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

Why are serialization and deserialization useful?

A

Transfer things across the network and save to harddrive

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

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

A

You write your code following JSON structure (quotes). JSON.stringify()

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

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

A

JSON.parse()

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

How to you store data in localStorage?

A

localStorage.setItem(‘key’, ‘keyValue’);

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

How to you retrieve data from localStorage?

A

localStorage.getItem(‘key’);

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

How to you store data in localStorage?

A

localStorage.setItem(‘key’, ‘keyValue’);

133
Q

What data type can localStorage save in the browser?

A

string

134
Q

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

A

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. Before the window is closed?

135
Q

What is a method?

A

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

136
Q

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

A

A method definition has the function keyword and the function code block. A method call only has the method name and any arguments it might require

137
Q

Describe method definition syntax (structure).

A

a method definition is stored in property of an object. The object is first defined, within the object definition is the method definition. The method name is the property then there’s a colon, the function key word, the parameter list, then the function code block

138
Q

Describe method call syntax (structure).

A

Object.method(arguments)

139
Q

How is a method different from any other function?

A

Since a method is a function that is a property of an object, no other objects can call a method that belongs to another object

140
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

141
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

142
Q

What is “abstraction”?

A

Being able to work with (possibly) complex things in simple ways.
Ex: Automatic gear shifting, turning on/off lightbulbs

143
Q

What does API stand for?

A

Application programming interface

144
Q

What is the purpose of an API?

A

In fact, the purpose of every software API is to give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction. A way to use complex behaviors without seeing the inner workings. People can still use it without really know how it works

145
Q

What is “this” in JavaScript?

A

It’s an implicit parameter, meaning 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

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

A

it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var. We can use it even when it is not explicitly defined

147
Q

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

A

Call time

148
Q

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

A

You won’t be able to tell until it the function or method is called

149
Q

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

A

look to the left of the period when the method is called. If there is nothing on the left of the period/ the function is being called by itself, ‘this’ refers to the global object window.

150
Q

What kind of inheritance does the JavaScript programming language use?

A

JavaScript includes a specific kind of inheritance known as prototype-based (or prototypal) inheritance

151
Q

What is a prototype in JavaScript?

A

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

152
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

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

153
Q

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

A

prototype object

154
Q

What does the new operator do?

A

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

155
Q

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

A

prototype property

156
Q

What does the instanceof operator do?

A

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

157
Q

What is a client?

A

A client is a piece of software or hardware that requests a service or resource.

158
Q

What is a server?

A

A server is a provider of a service or resource. They serve the client

159
Q

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

A

The GET method

160
Q

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

A
  1. An HTTP method, a verb (like GET, PUT or POST) or a noun (like HEAD or OPTIONS), that describes the action to be performed.
  2. The request target, usually a URL, or the absolute path of the protocol, port, and domain are usually characterized by the request context.
  3. The HTTP version, which defines the structure of the remaining message, acting as an indicator of the expected version to use for the response
161
Q

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

A
  1. The protocol version, usually HTTP/1.1.
  2. A status code, indicating success or failure of the request.
  3. A status text. A brief, purely informational, textual description of the status code to help a human understand the HTTP message.
162
Q

What are HTTP headers?

A

HTTP headers for responses follow the same structure as any other header: a case-insensitive string followed by a colon (‘:’) and a value whose structure depends upon the type of the header.

163
Q

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

A

MDN (?)

164
Q

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

A

No, responses with a status code that sufficiently answers the request without the need for corresponding payload usually don’t.

165
Q

What is AJAX?

A

Ajax refers to a group of technologies that offer asynchronous functionality in a browser. Ajax is being implemented when we only want to update one part of the page (without affecting the rest of the page)

166
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

167
Q

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

A

XMLHttpRequest

168
Q

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

A

load

169
Q

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

A

prototype inheritance

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

171
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

The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires.

172
Q

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

A
The setInterval() method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.
This method returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval().
173
Q

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

A

Defaults to 0 if not specified.

174
Q

What do setTimeout() and setInterval() return?

A
  • setTimeout() return a timeoutID which is a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout.
  • setInterval() returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval().
175
Q

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

A

A code block is the group of statements enclosed by curly bracs { }.
Examples: If-else, For loops, For In loops, While loops

176
Q

What does block scope mean?

A

This scope restricts the variable that is declared inside a specific block, from access by the outside of the block.
The variable can only be accessed within the block containing it

177
Q

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

A

block scope

178
Q

What is the difference between let and const?

A

variables declared with let can be reassigned, but those declared with const cannot be reassigned. The const keyword creates a read-only reference to a value. However, it doesn’t mean that the actual value to which the const variable reference is immutable.

179
Q

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

A

Although the const keyword creates a read-only reference to a value, the actual value is not immutable. The variable is read-only but the value the variable is referencing isn’t immutable. For example, for an object variable declared with the const keyword, the object can’t be “re-written”. However, the value of the object’s property can be changed by accessing the value of the property and assigning it a new value.

180
Q

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

A

If a variable’s value will need to be reassigned change, use let.
If not, use const.

181
Q

What is the syntax for writing a template literal?

A

Surround the string with backticks ` ` . Using backticks lets us use single or double quotes freely without escaping them

182
Q

What is “string interpolation”?

A

Substituting the value of a variable or expression within the template literal. This can be done by placing the variable or expression inside a code block: ${ }

183
Q

What are some features of the template literal?

A
  • A multiline string: a string that can span multiple lines.
  • String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.
  • HTML escaping: the ability to transform a string so that it is safe to include in HTML.
184
Q

What is destructuring, conceptually?

A

Destructuring is a JavaScript expression that allows us to extract data from arrays, objects, and maps and set them into new, distinct variables.

185
Q

What is the syntax for Object destructuring?

A

var, let, or const keyword followed by curly braces wtih key names (property names) followed by the assignment operator = and the object you are destructuring from

186
Q

What is the syntax for Array destructuring?

A

var, let, or const keyword followed by square brackets with a comma separated list of elements you want to destructure followed by the assignment operator = followed by the array you are destructuring from

187
Q

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

A

Destructuring has the braces and brackets on the left side of the assignment operator and the object/array name of the right side.
Creating an object/array has the name on the left side and the braces/brackets on the right side.

188
Q

What is the syntax for defining an arrow function?

A

(parameter list) => expression OR { code block };

189
Q

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

A

Without the curly braces, the return is implicit. With the curly braces, the return must be explicitly stated.

190
Q

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

A

Unlike an anonymous function, an arrow function captures the this value of the enclosing context instead of creating its own this context.
When ‘this’ is inside of a function, either stand alone or within another method, it will always refer to the window/global object.
It means that the arrow function uses these variables (or constructs) from the enclosing lexical scope.
The value of this is determined in function definition for arrow functions

191
Q

What is a CLI?

A

A command line interface processes commands to a computer program in the form of lines of text. Provides a means to pass commands to your computer through the prompt.

192
Q

What is a GUI?

A

A graphical user interface is a form of user interface that allows users to interact with electronic devices through icons, buttons, elements that are visually easy to understand. Ex. a common calculator app

193
Q
Give at least one use case for each of the commands listed in this exercise.
man
cat
ls
pwd
echo
touch
mkdir
mv
rm
cp
A

man - pulls up the system references manual. To look up commands
cat - concatenates files and prints them out on the interface. Displaying the contents of multiple files
ls - list the directory contents. To view the contents of a folder
pwd - prints the name of the current working directory. To get the full path of the current directory
echo - display a line of text. To display text and write it into another destination
touch - change file timestamps.
mkdir - make a directory. Create a child or parent directory
mv - move or rename a file.
rm - remove file or directory. To delete a file or folder
cp - copy files and directory. Make a copy of a file

194
Q

What are the three virtues of a great programmer?

A

Laziness, impatience, hubris

195
Q

What is Node.js?

A

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

196
Q

What can Node.js be used for?

A

It is commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.

197
Q

What is a REPL?

A

Read-eval-print-loop: An interactive programming environment that takes a single user input, executes it, and returns the result to the user. It is a loop because it waits for another input.

198
Q

When was Node.js created?

A

May 27, 2009

199
Q

What back end languages have you heard of?

A

PHP, C# (.net), Java, Python, ruby, perl, sql, typescript, go, haskell

200
Q

What is the difference between scripting languages and compiled languages?

A

Scripting languages are interpreted in real time. Also, compilers read and analyze the code only once, and report the errors collectively that the code might have, but the interpreter will read and analyze the code statements each time it meets them and halts at that very instance if there is some error.

201
Q

What is a computer process?

A

a process is the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity.

201
Q

What is a computer process?

A

a process is the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity.

202
Q

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

A

~500

203
Q

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

A

So your app doesn’t have high cpu and slow down the user’s computer

204
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(). It can also be explicitly accessed using require():
A model of the current node.js program

205
Q

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

A

Process object is global so it can be accessed by name

206
Q

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

A

an array string

207
Q

What does the array.map() method do?

A
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
const array1 = [ 1, 4, 9, 16 ];
// pass a function to map
const map1 = array1.map( x => x * 2 );
console.log(map1);
// expected output: Array [ 2, 8, 18, 32 ]
208
Q

What is a JavaScript module?

A

A JavaScript module is a single js file. It contains code to perform a specific task/function when called into a larger application.

209
Q

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

A

exports, require, module, __filename, __dirname

210
Q

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

A

process and global

The global object is all the global variables of the object.

211
Q

What is an anonymous function?

A

Anonymous Function is a function that does not have any name associated with it. Normally we use the function keyword before the function name to define a function in JavaScript, however, in anonymous functions in JavaScript, we use only the function keyword without the function name.

212
Q

What is a module wrapper function in the context of node.js?

A
Under the hood, NodeJS does not run our code directly, it wraps the entire code inside a function before execution. This function is termed as Module Wrapper Function. 
By wrapping the module in a wrapper function, the top-level variables declared with var, const, or let are scoped to the module rather than to the global object. Also global looking variables such as 
the module and exports object can be used to export values from the module.
The variables like  \_\_filename and \_\_dirname are also scoped to the module.
213
Q

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

A

Module exports are the instruction that tells Node. js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code.

214
Q

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

A
With the require function
require('module path')
215
Q

What is the JavaScript Event Loop?

A

The event loop is responsible for executing the code, collecting and processing events, and executing queued sub-tasks.

The event loop is a constantly running process that monitors both the callback queue and the call stack.

If the call stack is not empty, the event loop waits until it is empty and places the next function from the callback queue to the call stack. If the callback queue is empty, nothing will happen
on stack > API pool> on callback queu > on stack > pop off stack > next task on stack

216
Q

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

A

Blocking: It refers to the blocking of further operation until the current operation finishes. Blocking methods are executed synchronously. Synchronously means that the program is executed line by line. The program waits until the called function or the operation returns. Code that is blocking is on the stack and no other tasks can be completed until the stack is clear.
Non-Blocking: It refers to the program that does not block the execution of further operations. Non-Blocking methods are executed asynchronously. Asynchronously means that the program may not necessarily execute line by line. The program calls the function and move to the next operation and does not wait for it to return. Code that is anywhere but the stack

217
Q

What is a directory?

A

A file system that contains references to other files, and possibly other directories.

218
Q

What is a relative file path?

A

A relative path is a way to specify the location of a directory relative to another directory.

219
Q

What is an absolute file path?

A

An absolute path refers to the complete details needed to locate a file or folder, starting from the root element and ending with the other subdirectories.

220
Q

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

A

fs

221
Q

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

A

writeFile

222
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous unless the method has ‘sync’ in the name

223
Q

What is a client?

A

A piece of software or hardward that initiates a request for a service to a server

224
Q

What is a server?

A

A piece of software of hardware that receives requests and provides a service to its client or clients

225
Q

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

A

GET

226
Q

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

A

An http method (GET, PUT, POST), the request target (absolute url or absolute path; depends on the method used), the http version

227
Q

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

A

The http protocol version (usually HTTP/1.1), the status code that indicates whether the request succeeded or failed, and the status text (a short description that helps humans understand the status code)

228
Q

What are HTTP headers?

A

HTTP headers give more details about the request and the body included in the message. It is made up of a case sensitive string followed by a colon and value that depends on the header. There are general headers (ex: via; applies to the message as a whole), request headers (ex: Accept-Language), and representation headers (ex: Content-Type).

229
Q

Is a body required for a valid HTTP message?

A

No, it depends on the method being used. Ex: Some requests need to send data to the server using POST (form related data)

230
Q

What is a host?

A

A piece of hardware that runs a server and/or client program.

231
Q

What is the internet? What is the web?

A
232
Q

Give an example of a request over netcap

A
232
Q

Give an example of a request over netcap

A

nc example.com 80
GET / HTTP/1.1
Host: example.com

233
Q

How does HTTPie work?

A
  1. Enter a HTTPie command on the terminal
  2. The request is assembled (start-line). Internet connection is established.
  3. The request is sent
  4. The server receives request
  5. The server send back a response
  6. HTTPie prints the response to the terminal
234
Q

What is NPM?

A

npm is the world’s largest software registry. It is used to share and borrow packages. With npm you can share your code and other people’s code, incorporate packages to your apps. website, command line interface, registry.

235
Q

What is a package?

A

A package is a file or directory that is described by a package.json file.

a) A folder containing a program described by a package.json file.
b) A gzipped tarball containing (a).
c) A URL that resolves to (b).
d) A @ that is published on the registry with (c).
e) A @ that points to (d).
f) A that has a latest tag satisfying (e).
g) A git url that, when cloned, results in (a).

236
Q

How can you create a package.json with npm?

A

To create a default package.json go to your root directory for your package, then use the npm init command with the –yes or -y flag.
npm init –yes

237
Q

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

A

Packages required by your application in production. Code that relies on other code to work properly.
npm install < package name >

238
Q

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

A

Downloads the dependencies and puts it in the node-modules directory. The dependencies are updated on the package.json file

239
Q

How do you add express to your package dependencies?

A

npm install express

240
Q

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

A

listen - Binds and listens for connections on the specified host and port. This method is identical to Node’s http.Server.listen().

241
Q

How do you mount a middleware with an Express application?

A

use method
Bind application-level middleware to an instance of the app object by using the app.use() and app.METHOD() functions, where METHOD is the HTTP method of the request that the middleware function handles (such as GET, PUT, or POST) in lowercase.

242
Q

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

A

req and res

243
Q

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

A

Content-Type: application/json; charset=utf-8

244
Q

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

A

This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser.

Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body), or an empty object ({}) if there was no body to parse, the Content-Type was not matched, or an error occurred.

245
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a free, open source Relational Database Management System (RDBMS) with robust feature set, standards compliance, and reliability.
Some alternative relational databases are MySQL and SQL Server

246
Q

What are some advantages of learning a relational database?

A

they support good guarantees about data integrity. They can store and modify data in a way that makes data corruption as unlikely as possible. This means that developers can set up their database to reject “bad” data and not worry about data being “half written”. A lot of apps use data

247
Q

What is one way to see if PostgreSQL is running?

A

Open a new terminal and enter the ‘top’ command or the ‘sudo service postgresql status’

248
Q

What is a database schema?

A

A database schema is a collection of tables. A schema defines how the data in a relational database should be organized.

249
Q

What is a table?

A

A table is a list of rows each having the same set of attributes

250
Q

What is a row?

A

You might visualize a database table as a sort of spreadsheet where each row is a record in that spreadsheet

251
Q

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

A

Structured Query Language (SQL) is the primary way of interacting with relational databases. It is a powerful way of retrieving, creating, and manipulating data in a relational database. SQL is a declarative language whereas JavaScript is an imperative language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results.

252
Q

How do you retrieve specific columns from a database table?

A

select “columnName”, “columnName2”

from “tableName”;

253
Q

How do you filter rows based on some specific criteria?

A

where “columnName” = ‘value’

254
Q

What are the benefits of formatting your SQL?

A

It is easier to read

255
Q

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

A

, =, !=

256
Q

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

A

limit < number >

257
Q

How do you retrieve all columns from a database table?

A

select *

from “tableName”

258
Q

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

A

order by “columnName” asc/desc

259
Q

How do you add a row to a SQL table?

A

insert into “tableName” (“columnName”)

values (‘value’);

260
Q

What is a tuple?

A

In a relational database, a tuple is one record (one row) or a list of values that matches columns on a row

261
Q

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

A

Data rows can be batch inserted into a database table by specifying more than one tuple of values, separated by commas. Add another set of values in parantheses

262
Q

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

A

returning *

263
Q

How do you update rows in a database table?

A

update from “tableName”
set “columnName” = ‘value’
where ‘columnName” = ‘value’

264
Q

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

A

The where clause is used to target specific rows. Without it, you could potentially update all the rows

265
Q

How do you delete rows from a database table?

A

delete from “tableName”

where “columnName” = ‘value’

266
Q

How do you accidentally delete all rows from a table?

A

By leaving out the where clause

267
Q

What is a foreign key?

A

The column name that links two tables together. The tables have a common column name and values

268
Q

How do you join two SQL tables?

A

join “tableName” using (‘foreignKey’)

269
Q

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

A

“columnName” as “tempColumnName”

270
Q

What are some examples of aggregate functions?

A

max(), sum(), avg(), count()

271
Q

What is the purpose of a group by clause?

A

To perform aggregate functions on groups of rows. Groups are determined by discernable values in the same column

272
Q

What are the three states a Promise can be in?

A

pending: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.

273
Q

How do you handle the fulfillment of a Promise?

A

The associated handlers queued up by a promise’s then method are called.

274
Q

How do you handle the rejection of a Promise?

A

The catch() method returns a Promise and deals with rejected cases only. It behaves the same as calling Promise.prototype.then(undefined, onRejected) (in fact, calling obj.catch(onRejected) internally calls obj.then(undefined, onRejected)).

275
Q

What is Array.prototype.filter useful for?

A

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

276
Q

What is Array.prototype.reduce useful for?

A

The reduce() method is good for compiling the elements of an array into a single value

277
Q

What is Array.prototype.map useful for?

A

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

278
Q

What is “syntactic sugar”?

A

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

279
Q

What is the typeof an ES6 class?

A

a function

280
Q

Describe ES6 class syntax.

A
class keyword followed by className followed by curly braces.
Inside the curly braces there is an optional constructor method being defined where you can initialize the properties of an instance of the class.
281
Q

What is “refactoring”?

A

Changing the structor of existing code while maintaining the same external behavior. Advantages of refactoring include creating cleaner and simpler code

282
Q

What is Webpack?

A

It’s a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS), and it can be extended to support many different assets such as images, fonts and stylesheets.

Webpack is a static module bundler for JavaScript applications — it takes all the code from your application and makes it usable in a web browser.

Combines modules

283
Q

How do you add a devDependency to a package?

A

npm install < package-name > –save-dev

284
Q

What is an NPM script?

A

NPM Scripts are a set of built-in and custom scripts defined in the package.json file.

285
Q

How do you execute Webpack with npm run?

A

add a build property to script object with a value of “webpack”
npm run build

286
Q

How are ES Modules different from CommonJS modules?

A

Using exports and imports.
ES modules are part of the javascript language now
CommonJS are not part of the javascript language
Don’t use require or module.exports

287
Q

What kind of modules can Webpack support?

A

ES6 modules, commonJS modules, AMD modules, assets, web assembly modules

288
Q

What is React?

A

React is a JavaScript library for creating user interfaces.

289
Q

What is a React element?

A

An element describes what you want to see on the screen. Unlike browser DOM elements, React elements are plain objects, and are cheap to create. React DOM takes care of updating the DOM to match the React elements.

290
Q

How do you mount a React element to the DOM?

A

render() of the react DOM object

291
Q

What is Babel?

A

Babel is a JavaScript compiler
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.

292
Q

What is a Plug-in?

A

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

293
Q

What is a Webpack loader?

A

Loaders are transformations that are applied to the source code of a module. They allow you to pre-process files as you import or “load” them. Thus, loaders are kind of like “tasks” in other build tools and provide a powerful way to handle front-end build steps. Loaders can transform files from a different language (like TypeScript) to JavaScript or load inline images as data URLs. Loaders even allow you to do things like import CSS files directly from your JavaScript modules!

294
Q

How can you make Babel and Webpack work together?

A

npm install –save-dev babel-loader

295
Q

What is JSX?

A

a syntax extension to JavaScript used alongside React usually

296
Q

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

A

Since JSX compiles into calls to React.createElement, the React library must also always be in scope from your JSX code.

297
Q

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

A

connect webpack and babel with babel loader

install @babel/plugin-transform-react-jsx to convert JSX into valid JavaScript

298
Q

What is a React component?

A

Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen

299
Q

How do you define a function component in React?

A

The simplest way to define a component is to write a JavaScript function:

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}
300
Q

How do you mount a component to the DOM?

A

pass the return of the component function (react element) as an argument inside ReactDOM.render function call

301
Q

What are props in React?

A

You can pass any JavaScript expression as a prop, by surrounding it with {}. For example, in this JSX:

302
Q

How do you pass props to a component?

A

< componentName propName = prop value / >

303
Q

How do you write JavaScript expressions in JSX?

A

in between curly braces

304
Q

How do you create “class” component in React?

A
class ClassName extends React.Component {
     render() {
         return (
                React Element
         )
}
305
Q

How do you access props in a class component?

A

this.props

306
Q

What is the purpose of state in React?

A

React uses an observable object as the state that observes what changes are made to the state and helps the component behave accordingly. To keep track of values that change over time

307
Q

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

A
Define the callback function within the class component definition
Bind your event handler in the constructor definition
Assign the callback function to the event prop of the React element in the render() definition block
308
Q

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

A

map

309
Q

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

A

The best way to pick a key is to use a string that uniquely identifies a list item among its siblings.

310
Q

What does express.static() return?

A

express.static() serves static files (ex images, CSS files, and JavaScript file). It returns an object (?) [Function: serveStatic]

311
Q

What does express.static() return?

A

express.static() serves static files (ex images, CSS files, and JavaScript file). It returns a middleware function [Function: serveStatic]

312
Q

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

A

The absolute path of the directory of the current module. This is the same as the path.dirname() of the __filename.

313
Q

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

A

The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.

314
Q

What does fetch() return?

A

Returns a promise which is fulfilled once the response is available.

The promise resolves to the Response object representing the response to your request.

315
Q

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

A

GET

316
Q

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

A

specify the method in the method property within the second argument of the fetch method

317
Q

When does React call a component’s componentDidMount method?

A

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree), after a component is rendered

  • Constructor first
  • Then Render with initial state
  • componentDidMount 1 time after the first successful render
  • componentDidUpdate happens after each subsequent render
318
Q

Name three React.Component lifecycle methods.

A

constructor(), render(), componentDidMount()

319
Q

How do you pass data to a child component?

A

Passing it through a prop

320
Q

What is the lifecycle

A
321
Q

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

A

it returns a function

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

Creates a closure with an anonymous function that returns the value of “value”

323
Q

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

A

When it is defined

324
Q

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

A

At function definition, a lexical environment is created for the closure. Within the lexical environment, there can be variables that can be accessed by the inner function because of lexical scope. In closures, the javascript function maintain a reference to its lexical environment

325
Q

What does the acronym LIFO mean?

A

Last in, first out. The last thing pushed onto the stack is the first thing that can be poped out.

326
Q

What methods are available on a Stack data structure?

A

push and pop

327
Q

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

A

you must pop() until you get to the desired point in the stack

328
Q

What does the acronym FIFO mean?

A

First in first out. The first element that was added is the first element to be removed

329
Q

What methods are available on a Queue data structure?

A

enqueue(), dequeue()

330
Q

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

A

dequeue() until you reach the arbitrary point