JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To temporarily store bits of information a script needs to do its job

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

How do you declare a variable?

A

set a variable name to a variable keyword like var

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

set a value to the variable name with an assignment operator = < > …

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

What characters are allowed in variable names?

A

letters, dollar sign or underscore, it cannot start with a number

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

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

A

capitalization matters

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

strings are data types that consist of letters and other characters, enclosed in quotes, frequently used to add new content to a page

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

What is the purpose of a number?

A

for numeric data and counting, calculating sums, measurements, time, etc.

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 indicate whether something is true or false

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

the equals operator assigns a value to a variable

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

How do you update the value of a variable?

A

use the variable name and equals sign to assign it a new value

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

without setting a variable name to a variable keyword, the name will be null, without assigning a value to a variable, it will be undefined.

null is a nonexistent or invalid object

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

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

A

to help you debug code, so you know which variable is being logged

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

Give five examples of JavaScript primitives.

A

null, string, number, boolean, undefined, symbol, bigint

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

an expression?

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

What is string concatenation?

A

combining two strings into one

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

concatenation, addition, forcing a variable into a number, incrementing by one for a double plus

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

addition assignment, total += 1 would mean total = total + 1

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

What are objects used for?

A

storing multiple properties related to a variable

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

What are object properties?

A

variables that tell us about the object

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

Describe object literal notation.

A

an object’s properties and methods are assigned a variable name with the equals operator

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 object name . property name

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

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

A

dot notation or square bracket with property in quotes

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

What are arrays used for?

A

a list of values that are related to each other

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

Describe array literal notation.

A

name a variable and assign it values within brackets, separated by commas

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

because with arrays, the order matters. values are accessed by their numerical 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

the length property calculated the total number of indexes 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

.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

Functions are a series of instructions to be carried out when called.

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

functions begin with the function keyword, an optional name, (parameters, more, more, etc…), the function code block beginning with {, an optional return statement, and a closing } for the code block

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

Describe the parts of a function call.

A

a function call is initiated by the function name, parenthesis, and 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

a function definition does not include arguments, only parameters

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

What is the difference between a parameter and an argument?

A

parameters are placeholders for future arguments

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

Why are function parameters useful?

A

They allow you to use the function more than once

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

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

A
  1. It produces a value we can use.

2. It prevents any more code from being run.

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

Why do we log things to the console?

A

to debug, to ensure our code is working properly, to test a function before pairing it with another element

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

What is a method?

A

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

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

How is a method different from any other function?

A

A method is specifically tied to or contained within a function, some are built in, and we can add our own methods to objects.

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

How do you remove the last element from an array?

A

.pop()

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

with splice(), or shift()

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

with push() - which puts it at the end of the array, or unshift() which puts it at the beginning of the 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

with split() and an argument dictating where to split the array

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, you could console.log the original array after calling a method

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

around 60

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, like pop

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

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 the following code should continue running, to filter out edge cases, etc.

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 precedes the condition ( ) inside the condition are operands (values being compared) and an operator/s like < > ===, followed by opening curly brace for code block that will execute if condition is met ( or true )

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

by using and && or or ||

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 check a condition, if its true, the code block will run and then it’s checked again

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

to determine how many iterations a code will run

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

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

A

how many times the code block runs

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

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

A

before 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

the first time the code is run

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

immediately after the initialization expression and again until the condition is met

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

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

A

after the loop and until the condition is met

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

increment the counter by 1

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

How do you iterate through the keys of an object?

A

for in loop

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

Why is using !important considered bad practice?

A

It makes debugging more difficult by breaking the natural cascading in your stylesheets

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

Why do we log things to the console?

A

To check and debug code before continuing a function or passing values to other functions

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

What is a model

A

A facsimile, something that is representative of another thing, a prototype, an ideal, a platonic form

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

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

A

The html document

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

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

A

the pages elements are objects or nodes that you can access and navigate

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

What is a DOM Tree?

A

The dom tree is a js element for an html element with it’s properties, elements, children

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

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

A

getElementById and querySelector

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

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

A

getElementByClassName, getElementsByTagName, querySelectorAll

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

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

A

if you want to use the same element more than once. For instance, if you want to alter its innerHTML and setAttribute and addEventListener

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

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

A

1.If you have code in your JavaScript that alters HTML as soon as the JavaScript file loads, there won’t actually be any HTML elements available for it to affect yet, so it will seem as though the JavaScript code isn’t working, and you may get errors. 2.If you have a lot of JavaScript, it can visibly slow the loading of your page because it loads all of the JavaScript before it loads any of the HTML. When you place your JavaScript links at the bottom of your HTML body, it gives the HTML time to load before any of the JavaScript loads, which can prevent errors, and speed up website response time.

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

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

A

a css selector, and it returns the first matching element

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

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

A

a css selector, and it returns all that match

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

Why do we log things to the console?

A

to debug and see what we’re doing

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

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

A

No? Just the object

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

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

A

addEventListener

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

What is the purpose of events and event handling?

A

Events are fired to notify code of “interesting changes” that may affect code execution. These can arise from user interactions such as using a mouse or resizing a window, changes in the state of the underlying environment (e.g. low battery or media events from the operating system), and other causes.

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

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

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

A

an event type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
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 target property of the Event interface is a reference to the object onto which the event was dispatched. The element of where the event occurred.

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

What is the difference between these two snippets of code?

A

the second one is pointless because there are no arguments, both will fire the handleClick, but the first is the better option because the handleClick function may take arguments?

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

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

A

with the className property

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

What is the textContent property of element objects?

A

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

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

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

A

.textContent =

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

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

A

no, you can use an anonymous function right there and avoid it

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

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

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

A

by storing them in variables you can reuse them

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

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

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

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

A

input

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

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

A

submit

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

What does the event.preventDefault() method do?

A

stop the form info from being sent

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

the page refreshes

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

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

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

A

value

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

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

A

you don’t know where it’s wrong

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

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

A

you can use debugger and see what’s happening

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

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

A

No, not untill it’s appended

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

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

A

appendChild

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

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

A

name, value

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

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

A

createElement, createTextNode(optional), appendChild

create new element
store new element
query for parent element
call appendchild on parent with the new element as an argument

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

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

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

A

setAttribute with name, className

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

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

A

You can give that code a name, it’s easier to test, easier to reuse elsewhere

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

What is the event.target?

A

the place where the event occurred

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

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

A

event bubbling

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

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

A

element.tagname

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

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

A

The closest() method traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.

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

How can you remove an element from the DOM?

A

The Element.remove() method removes the element from the tree it belongs to.

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

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

What is the event.target?

A

where the event occurred

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.

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

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

after you query an element, and again after you create any new variable

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

we’d have to query the tab directly with querySelector

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

with a giant set of conditionals for each view

125
Q

What is a method?

A

A method is a function attached to an object

126
Q

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

A

a method definition lives inside an object and precedes a colon, a method call precedes a dot and is followed by parenthesis

127
Q

Describe method definition syntax (structure).

A

method: function (param) { return }

128
Q

Describe method call syntax (structure).

A

object.method()

129
Q

How is a method different from any other function?

A

A method belongs to an object

130
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects containing data and code, and the this/self notation, instances, class-based

Methods are behavior for actions to be done.

131
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

Encapsulation: In object-oriented programming (OOP), encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an object’s components.[1] Encapsulation is used to hide the values or state of a structured data object inside a class, preventing direct access to them by clients in a way that could expose hidden implementation details or violate state invariance maintained by the methods.

Publicly accessible methods are generally provided in the class to access or modify the state more abstractly. In practice sometimes methods (so-called “getters” and “setters”) are provided to access the values indirectly, but, although not necessarily a violation of abstract encapsulation, they are often considered a sign-post of potentially poor object-oriented programming (OOP) design practice [2] (an Anti-pattern).

Inheritance: In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance), retaining similar implementation. Also defined as deriving new classes (sub classes) from existing ones such as super class or base class and then forming them into a hierarchy of classes. In most class-based object-oriented languages, an object created through inheritance, a “child object”, acquires all the properties and behaviors of the “parent object” , with the exception of: constructors, destructor, overloaded operators and friend functions of the base class. Inheritance allows programmers to create classes that are built upon existing classes,[1] to specify a new implementation while maintaining the same behaviors (realizing an interface), to reuse code and to independently extend original software via public classes and interfaces. The relationships of objects or classes through inheritance give rise to a directed graph.

Polymorphism: In programming languages and type theory, polymorphism is the provision of a single interface to entities of different types[1] or the use of a single symbol to represent multiple different types.[2]The concept is borrowed from a principle in biology where an organism or species can have many different forms or stages.[3]

132
Q

What is “abstraction”?

A

Abstraction is being able to work with complex things in simple ways. The DOM is an abstraction of the html document, not the actual document.

the creation of abstract concept-objects by mirroring common features or attributes of various non-abstract objects or systems of study[3] – the result of the process of abstraction.
Abstraction, in general, is a fundamental concept in computer science and software development.[4] The process of abstraction can also be referred to as modeling and is closely related to the concepts of theory and design.[5] Models can also be considered types of abstractions per their generalization of aspects of reality.

133
Q

What does API stand for?

A

Application Programming Interface

134
Q

What is the purpose of an API?

A

To hide the internal details of how a system works, exposing only those parts a programmer will find particularly useful

135
Q

What is this in JavaScript?

A

this is an implicit parameter of all javascript objects, this is the object you’re current’y working with

136
Q

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

A

it’s available in the function code-block even though it was never given as an argument

137
Q

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

A

call time baby

138
Q

What does this refer to in the following code snippet?

A

the character object

139
Q

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

A

nothing because it hasn’t been called yet

140
Q

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

A

It’s me, mario!

Because you just assigned a variable to the character method greet

141
Q

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

A

you can’t, it’s a parameter and it doesn’t have a value until called

142
Q

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

A

whatever the properties of the object it’s being called from, left of the dot

143
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based programming is a style of object-oriented programming in which behaviour reuse (known as inheritance) is performed via a process of reusing existing objects that serve as prototypes. This model can also be known as prototypal, prototype-oriented, classless, or instance-based programming.

144
Q

What is a prototype in JavaScript?

A

generalized object that can be reused, cloned, extended, etc. Array prototypes are applied to every array.

145
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

Because there are string, array, and number prototypes

146
Q

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

A

the prototype

147
Q

What does the new operator do?

A

The new keyword does the following things:

Creates a blank, plain JavaScript object.

Adds a property to the new object (__proto__) that links to the constructor function’s prototype object

Note: Properties/objects added to the construction function prototype are therefore accessible to all instances created from the constructor function (using new).

Binds the newly created object instance as the this context (i.e. all references to this in the constructor function now refer to the object created in the first step).
Returns this if the function doesn’t return an object.

148
Q

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

A

prototype

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

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

151
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

setInterval setTimeout

152
Q

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

A

setInterval

153
Q

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

A

0

154
Q

What do setTimeout() and setInterval() return?

A

the timeOutID

The returned timeoutID 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.

It is guaranteed that a timeoutID value will never be reused by a subsequent call to setTimeout() or setInterval() on the same object (a window or a worker). However, different objects use separate pools of IDs.

155
Q

What is a client?

A

Client–server model is a distributed application structure that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients.[1] Often clients and servers communicate over a computer network on separate hardware, but both client and server may reside in the same system. A server host runs one or more server programs, which share their resources with clients. A client usually does not share any of its resources, but it requests content or service from a server. Clients, therefore, initiate communication sessions with servers, which await incoming requests. Examples of computer applications that use the client–server model are email, network printing, and the World Wide Web.

https://en.wikipedia.org/wiki/Client%E2%80%93server_model

156
Q

What is a server?

A

A server host runs one or more server programs, which share their resources with clients.

The “client-server” characteristic describes the relationship of cooperating programs in an application. The server component provides a function or service to one or many clients, which initiate requests for such services. Servers are classified by the services they provide. For example, a web server serves web pages and a file server serves computer files. A shared resource may be any of the server computer’s software and electronic components, from programs and data to processors and storage devices. The sharing of resources of a server constitutes a service.

Whether a computer is a client, a server, or both, is determined by the nature of the application that requires the service functions. For example, a single computer can run web server and file server software at the same time to serve different data to clients making different kinds of requests. Client software can also communicate with server software within the same computer.[2] Communication between servers, such as to synchronize data, is sometimes called inter-server or server-to-server communication.

157
Q

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

A

GET (Post, Head Options)

to send data to the server/database, POST

158
Q

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

A

A start-line describing the requests to be implemented, or its status of whether successful or a failure. This start-line is always a single line.

An optional set of HTTP headers specifying the request, or describing the body included in the message.

A blank line indicating all meta-information for the request has been sent.

An optional body containing data associated with the request (like content of an HTML form), or the document associated with a response. The presence of the body and its size is specified by the start-line and HTTP headers.

159
Q

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

A

The protocol version, usually HTTP/1.1.
A status code, indicating success or failure of the request. Common status codes are 200, 404, or 302
A status text. A brief, purely informational, textual description of the status code to help a human understand the HTTP message.

160
Q

What are HTTP headers?

A

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

161
Q

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

A

MDN on HTTP Headers

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

162
Q

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

A

The last part of a response is the body. Not all responses have one: responses with a status code that sufficiently answers the request without the need for corresponding payload (like 201 Created or 204 No Content) usually don’t.

Bodies can be broadly divided into three categories:

Single-resource bodies, consisting of a single file of known length, defined by the two headers: Content-Type and Content-Length.
Single-resource bodies, consisting of a single file of unknown length, encoded by chunks with Transfer-Encoding set to chunked.
Multiple-resource bodies, consisting of a multipart body, each containing a different section of information. These are relatively rare.

163
Q

What is AJAX?

A

Ajax is a technique for loading data into part of a page without having to refresh the entire page. The data is often sent in a format called JavaScript Object Notation or JSON

164
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

165
Q

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

A

XMLHttpRequest

var requestVariable = new XMLHttpRequest()
requestVarialbe.open('GET', 'filepath.json', true)
reqeustVariable.send ('search=pepperoni')

reponse

requestVariable.onload = function() {
}

166
Q

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

A

load

167
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

they both share a prototype

168
Q

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

A

function code block, if block, conditional code block, object code block

169
Q

What does block scope mean?

A

the variable is contained within the block of code, it isn’t globally accessible, it’s only accessible within the code block

170
Q

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

A

They are both block scoped variables

171
Q

What is the difference between let and const?

A

the variables declared by the const keyword cannot be reassigned

172
Q

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

A

you can mutate the array, but you cannot reassign the variable to another array or something else entirely

173
Q

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

A

If you’re going to be reassigning the value of a variable each iteration, like a loop and i, you should use let, otherwise use const

174
Q

What is the syntax for writing a template literal?

A

a string with backticks instead of quotes

175
Q

What is “string interpolation”?

A

String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.

176
Q

What is destructuring, conceptually?

A

flattening the object literal structure and flipping it around so you can declare and assign properties/values before assigning the abject or array a variable name

177
Q

What is the syntax for Object destructuring?

A

let { property: value, property: value} = variable name

178
Q

What is the syntax for Array destructuring?

A

let [ variable, another variable, …] = function() that returns array

179
Q

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

A

destructuring is done in the opposite format and set equal to the object/array

180
Q

What is the syntax for defining an arrow function?

A

function nam = (params) => return

181
Q

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

A

nothing

182
Q

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

A

by the following surrounding scope

183
Q

What is a CLI?

A

command line interface

184
Q

What is a GUI?

A

graphical user interface

185
Q

man

A

you need to find a specific command

186
Q

cat

A

when you want to combine similar files into another directory

187
Q

ls

A

when you need to see the contents of a directory

188
Q

pwd

A

when you need the filepath

189
Q

echo

A

prints a string

190
Q

touch

A

when you want to make a new file

191
Q

mkdir

A

when you want to make a new directory/folder

192
Q

mv

A

renames or moves

193
Q

rm

A

removes

194
Q

cp

A

copies

195
Q

What is Node.js?

A

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

Node.js is similar in design to, and influenced by, systems like Ruby’s Event Machine and Python’s Twisted. Node.js takes the event model a bit further. It presents an event loop as a runtime construct instead of as a library. In other systems, there is always a blocking call to start the event-loop. Typically, behavior is defined through callbacks at the beginning of a script, and at the end a server is started through a blocking call like EventMachine::run(). In Node.js, there is no such start-the-event-loop call. Node.js simply enters the event loop after executing the input script. Node.js exits the event loop when there are no more callbacks to perform. This behavior is like browser JavaScript — the event loop is hidden from the user.

HTTP is a first-class citizen in Node.js, designed with streaming and low latency in mind. This makes Node.js well suited for the foundation of a web library or framework.

196
Q

What can Node.js be used for?

A

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser. Consequently, Node.js represents a “JavaScript everywhere” paradigm,[6] unifying web-application development around a single programming language, rather than different languages for server-side and client-side scripts.

197
Q

What is a REPL?

A

A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise.[1] The term is usually used to refer to programming interfaces similar to the classic Lisp machine interactive environment. Common examples include command-line shells and similar environments for programming languages, and the technique is very characteristic of scripting languages.[2

198
Q

When was Node.js created?

A

may 27 2009 by ryan dahl

199
Q

What back end languages have you heard of?

A

Python

200
Q

What is a computer process?

A

In computing, 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. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.[1][2]

201
Q

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

A

528

202
Q

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

A

Full stack Web development is based on making multiple processes work together to form one application, so having at least a cursory awareness of computer processes is necessary. This will be extremely important when learning about applications made of multiple components, such as clients, servers, and databases.

so they know how much memory their application takes up, whether all threads are running concurrently, and which part of the application is causing issues (front or back end)

203
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():

204
Q

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

A

require ‘process’

205
Q

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

A

array of strings

206
Q

what is a JavaScript module?

A

a single js file

207
Q

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

A

(exports, require, module, __filename, __dirname)

__dirname: directory name of current module, same as the path.dirname() of the __filename

\_\_filename
The file name of the current module. This is the current module file's absolute path with symlinks resolved.

For a main program this is not necessarily the same as the file name used in the command line.

exports#
Added in: v0.1.12

A reference to the module.exports that is shorter to type. See the section about the exports shortcut for details on when to use exports and when to use module.exports.

module#
Added in: v0.1.16

A reference to the current module, see the section about the module object. In particular, module.exports is used for defining what a module exports and makes available through require().

require(id)#
Added in: v0.1.13
id  module name or path
Returns:  exported module content
Used to import modules, JSON, and local files. Modules can be imported from node_modules. Local modules and JSON files can be imported using a relative path (e.g. ./, ./foo, ./bar/baz, ../foo) that will be resolved against the directory named by \_\_dirname (if defined) or the current working directory. The relative paths of POSIX style are resolved in an OS independent fashion, meaning that the examples above will work on Windows in the same way they would on Unix systems.
208
Q

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

A

Abort controller: A utility class used to signal cancelation in selected Promise-based APIs. The API is based on the Web API AbortController.

process object: 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():

209
Q

what is the JavaScript Event Loop

A

JavaScript is single-threaded, meaning it can only execute one function at a time, but the event loop an dit’s queue/stack give the illusion that it’s multithreaded and non-blocking

the event loop pulls things (generally functions) out of the queue and places them onto the execution stack whenever the stack becomes empty, giving the illusion that javascript is multithreaded even though it is single threaded

so, when the stack executes setTimeOut, setTimeOut’s callback funciton is pushed into the web API where it waits. It’s then pushed to the queue were it waits until the stack is empty, then it’s pushed into the stack for execution.

210
Q

what’s the difference between blocking and non-blocking?

A

blocking means nothing else can happen until it’s complete, non-blocking is like setTimeout or asynchronous functions that can execute in the order of the call stack, or the next time the event loop comes around and moves it out of the queue

non-blocking is synchronous execution of code, one after another regardless of time complexity

non-blocking means code can run asynchronously. With node, that means larger functions can be pushed into thread pools while smaller functions are handled by the event loop

211
Q

What is a directory?

A

A directory is a folder

212
Q

What is a relative file path?

A

A path that begins with the current directory

213
Q

What is an absolute path?

A

A path that contains the root directory and all other subdirectories

214
Q

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

A

fs (file system)

215
Q

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

A

fs.writeFile

216
Q

Are file operations using the fs module synchronous or asynchronous?

A

fs.writeFile is asynchronous, while fs.writeFileSync is synchronous aka it blocks the event loop

217
Q

What is a client?

A

a service requester / browser

Client–server model is a distributed application structure that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients.[1] Often clients and servers communicate over a computer network on separate hardware, but both client and server may reside in the same system. A server host runs one or more server programs, which share their resources with clients. A client usually does not share any of its resources, but it requests content or service from a server. Clients, therefore, initiate communication sessions with servers, which await incoming requests. Examples of computer applications that use the client–server model are email, network printing, and the World Wide Web.

218
Q

What is a server?

A

The server component provides a function or service to one or many clients, which initiate requests for such services. Servers are classified by the services they provide. For example, a web server serves web pages and a file server serves computer files. A shared resource may be any of the server computer’s software and electronic components, from programs and data to processors and storage devices. The sharing of resources of a server constitutes a service.

Generally, a service is an abstraction of computer resources and a client does not have to be concerned with how the server performs while fulfilling the request and delivering the response. The client only has to understand the response based on the well-known application protocol, i.e. the content and the formatting of the data for the requested service.

Clients and servers exchange messages in a request–response messaging pattern. The client sends a request, and the server returns a response. This exchange of messages is an example of inter-process communication. To communicate, the computers must have a common language, and they must follow rules so that both the client and the server know what to expect. The language and rules of communication are defined in a communications protocol. All protocols operate in the application layer. The application layer protocol defines the basic patterns of the dialogue. To formalize the data exchange even further, the server may implement an application programming interface (API).[3] The API is an abstraction layer for accessing a service. By restricting communication to a specific content format, it facilitates parsing. By abstracting access, it facilitates cross-platform data exchange.[4]

A server may receive requests from many distinct clients in a short period of time. A computer can only perform a limited number of tasks at any moment, and relies on a scheduling system to prioritize incoming requests from clients to accommodate them. To prevent abuse and maximize availability, the server software may limit the availability to clients. Denial of service attacks are designed to exploit a server’s obligation to process requests by overloading it with excessive request rates. Encryption should be applied if sensitive information is to be communicated between the client and the server.

219
Q

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

A

GET

220
Q

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

A

GET / HTTP/1.1

221
Q

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

A

HTTP/1.1 200 OK (if it’s okay)

222
Q

What are HTTP headers?

A

Key value pairs.

HTTP headers from a request follow the same basic structure of an HTTP header: a case-insensitive string followed by a colon (‘:’) and a value whose structure depends upon the header. The whole header, including the value, consist of one single line, which can be quite long.

223
Q

Is a body required for a valid HTTP message?

A

Not all requests have one: requests fetching resources, like GET, HEAD, DELETE, or OPTIONS, usually don’t need one. Some requests send data to the server in order to update it: as often the case with POST requests (containing HTML form data).

224
Q

What is NPM?

A

npm is the world’s largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.

npm consists of three distinct components:

the website
the Command Line Interface (CLI)
the registry
Use the website to discover packages, set up profiles, and manage other aspects of your npm experience. For example, you can set up organizations to manage access to public or private packages.

The CLI runs from a terminal, and is how most developers interact with npm.

The registry is a large public database of JavaScript software and the meta-information surrounding it.

Use npm to . . .
Adapt packages of code for your apps, or incorporate packages as they are.
Download standalone tools you can use right away.
Run packages without downloading using npx.
Share code with any npm user, anywhere.
Restrict code to specific developers.
Create organizations to coordinate package maintenance, coding, and developers.
Form virtual teams by using organizations.
Manage multiple versions of code and code dependencies.
Update applications easily when underlying code is updated.
Discover multiple ways to solve the same puzzle.
Find other developers who are working on similar problems and projects.

225
Q

What is a package?

A

A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry. For more information on creating a package.json file, see “Creating a package.json file”.

Packages can be unscoped or scoped to a user or organization, and scoped packages can be private or public.

About package formats
A package is any of the following:

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

226
Q

How can you create a package.json with npm?

A

npm init

227
Q

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

A

packages your project depends on, listed as “dependencies” in your package.json file or “devDependencies”

to add dependencies to a package.json under devDependencies, you use the command line and do:

npm install –save-dev

228
Q

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

A

npm will download that dependency when you run npm install, or whenever your package runs

229
Q

How do you add express to your package dependencies?

A

npm install express

230
Q

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

A

.listen

231
Q

How do you mount a middleware with an Express application?

A

.use method

232
Q

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

A

req res

233
Q

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

A

application/json

234
Q

what is the significance of the HTTP request method

A

it tells you what the client is asking for/doing

235
Q

what is express.json()

A

express.json() parses incoming json, .json() converts outgoing objects into json

236
Q

What is PostgreSQL and what are some alternative relational databases?

A

A relational database is a digital database based on the relational model of data, as proposed by E. F. Codd in 1970.[1] A system used to maintain relational databases is a relational database management system (RDBMS). Many relational database systems have an option of using the SQL (Structured Query Language) for querying and maintaining the database.[2]

the relational model organizes into columns and rows, with a unique key identifying each row

Oracle Database
IBM Db2
Microsoft SQL Server
Microsoft Access
SAP

As is typical of client/server applications, the client and the server can be on different hosts. In that case they communicate over a TCP/IP network connection. You should keep this in mind, because the files that can be accessed on a client machine might not be accessible (or might only be accessible using a different file name) on the database server machine.

The PostgreSQL server can handle multiple concurrent connections from clients. To achieve this it starts (“forks”) a new process for each connection. From that point on, the client and the new server process communicate without intervention by the original postgres process. Thus, the supervisor server process is always running, waiting for client connections, whereas client and associated server processes come and go. (All of this is of course invisible to the user. We only mention it here for completeness.)

237
Q

What are some advantages of learning a relational database?

A

They can make it easy to access, organize, and protect data

238
Q

What is one way to see if PostgreSQL is running?

A

sudo service postgresql status

239
Q

What is a table?

A

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

240
Q

What is a row?

A

The values for each row correspond to the attribute names

241
Q

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

A

SQL is a declarative programming language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results.

242
Q

How do you retrieve specific columns from a database table?

A

with a select statement

243
Q

How do you filter rows based on some specific criteria?

A

The query starts with the select keyword.
The select keyword is followed by a comma-separated list of column names, each surrounded by “ double quotes.
The column names are followed by a from clause specifying which table to retrieve the data from.
The query must end in a ; semicolon.
SQL keywords such as select and from are not case-sensitive.
SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.

244
Q

How do you filter rows based on some specific criteria?

A

where “category” = ‘somecategory’;

245
Q

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

A

< > != =

246
Q

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

A

limit #;

247
Q

How do you retrieve all columns from a database table?

A

select *

248
Q

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

A

order by ____ desc; or asc;

249
Q

How do you add a row to a SQL table?

A

an insert statement

250
Q

What is a tuple?

A

a turple is a set/batch of values

251
Q

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

A

by using multiple turples, parenthetical sets of values

252
Q

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

A

with returning *;

253
Q

How do you update rows in a database table?

A

with the update clause

254
Q

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

A

so you can be specific about what you’re updating and not update everything

255
Q

How do you delete rows from a database table?

A

with a delete clause

256
Q

How do you accidentally delete all rows from a table?

A

you don’t specify rows or columns

257
Q

What is a foreign key?

A

a column that’s shared between two tables

258
Q

How do you join two SQL tables?

A

with a join clause

select *
from “products”
join “suppliers” using (“supplierId”);

259
Q

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

A

alias column names

260
Q

What are some examples of aggregate functions?

A

max(), avg(), min(), sum(), every(),

select max(“price”) as “highestPrice” from “products”

select avg(“price”) as “averagePrice” from “products”

select count(*) as “totalProducts” from “products”

261
Q

What is the purpose of a group by clause?

A

so you can specify certain rows, not the entire table

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

263
Q

How do you handle the fulfillment of a Promise?

A

with resolve

264
Q

How do you handle the rejection of a Promise?

A

with reject

265
Q

What is map useful for

A

for creating a new array from specific elements

266
Q

What is Array.prototype.reduce useful for?

A

Combining the elements of an array into a single value.

267
Q

What is “syntactic sugar”?

A

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language “sweeter” for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

For example, many programming languages provide special syntax for referencing and updating array elements. Abstractly, an array reference is a procedure of two arguments: an array and a subscript vector, which could be expressed as get_array(Array, vector(i,j)). Instead, many languages provide syntax such as Array[i,j]. Similarly an array element update is a procedure consisting of three arguments, for example set_array(Array, vector(i,j), value), but many languages provide syntax such as Array[i,j] = value.

A construct in a language is syntactic sugar if it can be removed from the language without any effect on what the language can do: functionality and expressive power will remain the same.

Language processors, including compilers and static analyzers, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called “desugaring”.

268
Q

What is the typeof an ES6 class?

A

a function

269
Q

Describe ES6 class syntax.

A
class VariableName {
constructor(variable) {
this.variable = variable
}
methods() {
return this.whatever
}

This Person class behaves like the Person type in the previous example. However, instead of using a constructor/prototype pattern, it uses the class keyword.

In the Person class, the constructor() is where you can initialize the properties of an instance. JavaScript automatically calls the constructor() method when you instantiate an object of the class.

270
Q

What is “refactoring”?

A

In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality. Potential advantages of refactoring may include improved code readability and reduced complexity; these can improve the source code’s maintainability and create a simpler, cleaner, or more expressive internal architecture or object model to improve extensibility. Another potential goal for refactoring is improved performance; software engineers face an ongoing challenge to write programs that perform faster or use less memory.

Typically, refactoring applies a series of standardised basic micro-refactorings, each of which is (usually) a tiny change in a computer program’s source code that either preserves the behaviour of the software, or at least does not modify its conformance to functional requirements. Many development environments provide automated support for performing the mechanical aspects of these basic refactorings. If done well, code refactoring may help software developers discover and fix hidden or dormant bugs or vulnerabilities in the system by simplifying the underlying logic and eliminating unnecessary levels of complexity. If done poorly, it may fail the requirement that external functionality not be changed, and may thus introduce new bugs.

By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you’ll find that it is easier to extend and maintain code.

— Joshua Kerievsky, Refactoring to Patterns[1]

271
Q

What is Webpack?

A
Wouldn't it be nice…
...to have something that will not only let us write modules but also support any module format (at least until we get to ESM) and handle resources and assets at the same time?

This is why webpack exists. 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 cares about performance and load times; it’s always improving or adding new features, such as async chunk loading and prefetching, to deliver the best possible experience for your project and your users.

272
Q

How do you add a devDependency to a package?

A

npm install package name –save-dev

273
Q

What is an NPM script?

A

The “scripts” property of your package.json file supports a number of built-in scripts and their preset life cycle events as well as arbitrary scripts. These all can be executed by running npm run-script or npm run for short. Pre and post commands with matching names will be run for those as well (e.g. premyscript, myscript, postmyscript). Scripts from dependencies can be run with npm explore – npm run .

274
Q

How are ES Modules different from CommonJS modules?

A

Being built into the language allows ES6 modules to go beyond CommonJS and AMD (details are explained later):

Their syntax is even more compact than CommonJS’s.
Their structure can be statically analyzed (for static checking, optimization, etc.).
Their support for cyclic dependencies is better than CommonJS’s.
The ES6 module standard has two parts:

Declarative syntax (for importing and exporting)
Programmatic loader API: to configure how modules are loaded and to conditionally load modules

If you require a library in CommonJS, you get back an object:

var lib = require('lib');
lib.someFunc(); // property lookup
Thus, accessing a named export via lib.someFunc means you have to do a property lookup, which is slow, because it is dynamic.

In contrast, if you import a library in ES6, you statically know its contents and can optimize accesses:

import * as lib from ‘lib’;
lib.someFunc(); // statically resolved

With a static module structure, you always statically know which variables are visible at any location inside the module:

Global variables: increasingly, the only completely global variables will come from the language proper. Everything else will come from modules (including functionality from the standard library and the browser). That is, you statically know all global variables.
Module imports: You statically know those, too.
Module-local variables: can be determined by statically examining the module.

275
Q

What kind of modules can Webpack support?

A
ECMAScript modules
CommonJS modules
AMD modules
Assets
WebAssembly modules
276
Q

What is React?

A

React is a Javascript Framework/library that makes it easy to make reusable components that encapsulate html and logic into a class or function

Makes it easy to build modular applications

We can finally stop making giant DOM trees

277
Q

What is a React element?

A

Elements are the smallest building blocks of react apps. A react element describes what you want to see on the screen. Unlike browser dom elements, react elements are plain object and are cheap to create. React dom takes care of updating the dom to match the react elements. Elements are what components are made of.

278
Q

How do you mount a React element to the DOM?

A

By using ReactDOM.render, which is only called when the element changes

React DOM compares the element and its children to the previous one and only applies DOM updates necessary to bring the hhhhhhhhhhDOM to the desired state

279
Q

What is Babel?

A

Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. Here are the main things Babel can do for you:

Transform syntax
Polyfill features that are missing in your target environment (through a third-party polyfill such as core-js)
Source code transformations (codemods)
And more! (check out these videos for inspiration)

280
Q

What is a Plug-in?

A

A software component that adds a specific feature to an existing program, often supporting customization. Like a theme or skin preset package that can change the GUI.

281
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!

282
Q

How can you make Babel and Webpack work together?

A

npm install -D babel-loader @babel/core @babel/preset-env webpack

283
Q

What is JSX?

A

A syntax extension of javascript

Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props, …children) function.

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

285
Q

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

A

‘@babel/plugin-transform-react-jsx’

286
Q

What is a React component?

A

Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to the idea of components. You can find a detailed component API reference here.

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

287
Q

How do you define a function component in React?

A

the same way you do for a javascript function with props as a parameter and returning jsx

288
Q

How do you mount a component to the DOM?

A

you create an element out of your function, then use reactdom.render and pass in the element along with document.querySelector(“#root”)

289
Q

What are controlled components?

A

In HTML, form elements such as , , and typically maintain their own state and update it based on user input. In React, mutable state is typically kept in the state property of components, and only updated with setState().

We can combine the two by making the React state be the “single source of truth”. Then the React component that renders a form also controls what happens in that form on subsequent user input. An input form element whose value is controlled by React in this way is called a “controlled component”.

290
Q

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

A

onChange/Value

291
Q

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

A

map

292
Q

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

A

id

293
Q

what does express.static() do?

A

This is a built-in middleware function in Express. It serves static files and is based on serve-static.

The root argument specifies the root directory from which to serve static assets. The function determines the file to serve by combining req.url with the provided root directory. When a file is not found, instead of sending a 404 response, it instead calls next() to move on to the next middleware, allowing for stacking and fall-backs.

294
Q

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

A

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

295
Q

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

A

…paths A sequence of path segments
Returns:
The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.

Zero-length path segments are ignored. If the joined path string is a zero-length string then ‘.’ will be returned, representing the current working directory.

path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
// Returns: '/foo/bar/baz/asdf'
path.join('foo', {}, 'bar');
// Throws 'TypeError: Path must be a string. Received {}'
296
Q

What does fetch() return?

A

a promise

The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.

This kind of functionality was previously achieved using XMLHttpRequest. Fetch provides a better alternative that can be easily used by other technologies such as Service Workers. Fetch also provides a single logical place to define other HTTP-related concepts such as CORS and extensions to HTTP.

The fetch specification differs from jQuery.ajax() in the following significant ways:

The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, as soon as the server responds with headers, the Promise will resolve normally (with the ok property of the response set to false if the response isn’t in the range 200–299), and it will only reject on network failure or if anything prevented the request from completing.
fetch() won’t send cross-origin cookies unless you set the credentials init option. (Since April 2018. The spec changed the default credentials policy to same-origin. Firefox changed since 61.0b13.)

297
Q

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

A

GET?

298
Q

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

A

const fetchResponsePromise = fetch(resource [, init])

299
Q

When does React call a component’s componentDidMount method?

A

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.

300
Q

Name three React.Component lifecycle methods.

A

ComponentWillUnmount, ComponentDidMount, Render, ComponentDidUpdate

301
Q

How do you pass data to a child component?

A

via props

302
Q

What are closures?

A

A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.

303
Q

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

A

the return value must be a function

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

the function wrap is being defined with one argument, value, which return an anonymous function. The anonymous function returns the argument value

305
Q

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

A

defined

306
Q

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

A

the lexical scope - the location where the variable is declared. nested functions have access to outer functions variables, but not the other way around