JavaScript Flashcards

1
Q

What is the purpose of variables?

A

store information for use later

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

How do you declare a variable?

A

var keyword eg var fullName

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

assignment operator =

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

What characters are allowed in variable names?

A

letters, numbers, dollar sign, underscore

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

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

A

upper case and lower case are treated independntly. eg car is not the same as Car

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

represent text

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

What is the purpose of a number?

A

represent numeric data type

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

represent 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

assignment eg var name = “jon”

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

variable name = (new value)

note that keyword var is not needed

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

What is the difference between null and undefined?

A

undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.

a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address.

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

clarity in the output - makes it easier to identify.

A console log “label” is simply a short string that describes the variable or value 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

string, number, Boolean, undefined, null – bigint, symbol

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

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

joining together strings

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

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

A

addition and concatenation

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

What data type is returned by comparing two values (, ===, etc)?

A

boolean

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

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

A

addition assignment, adds value and assigns the result to the variable

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

What are objects used for?

A

group together a set of properties and methods

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

What are object properties?

A

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
similar to css rulesets.
var hotel = {
name: "quay"
}
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 keyword followed by the property name and object 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
object.property

bracket notation
object{‘property’]

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

What are arrays used for?

A

storing a list of values that are related to each other

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

Describe array literal notation.

A

colors = [‘red’, ‘white’, ‘blue’]

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

the key for a value in an array is its index number
order matters in an array
arrays have length property
each piece of data is not named

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

holds the number of items in an array

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

How do you calculate the last index of an array?

A

array.length - 1

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

What is a function in JavaScript?

A

a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the 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,
name of the function,
function parameters,
javascript statements in curly braces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Describe the parts of a function call.

A

name of the function, parenthesis with parameters

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

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

A

function call does not need the function keyword and includes the values for the 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

parmeter - placeholder for an argument, value is not known until argument is passed.

argument- actual values passed to the function in place of the parameter

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

Why are function parameters useful?

A

they act as placeholders

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

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

A

causes the function to produce a value we can use in our program

exits the code block

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

Why do we log things to the console?

A

so we can see the output (debugging tool)

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

What is a method?

A

a function as a property inside 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

method is associated with an object

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

How do you remove the last element from an array?

A

with the pop method

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

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

A

with the floor method

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

How do you generate a random number?

A

random method of the math object

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

How do you delete an element from an array?

A

splice method

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

How do you append an element to an array?

A

push method

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

How do you break a string up into an array?

A

split method

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

Do string methods change the original string? How would you check if you weren’t sure?

A

No,

console log the original string

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

Is the return value of a function or method useful in every situation?

A

no. eg push will return length of new string

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

Give 6 examples of comparison operators.

A
not equal to (!=)
strict equal to (===)
><
>=
<=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

What data type do comparison expressions evaluate to?

A

boolean, true or false

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

What is the purpose of an if statement?

A

evaluates a condition, if condition is true then the code block is executed

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

Describe the syntax (structure) of an if statement.

A

keyword, condition, opening curly brace

if (condition >= condition) {

}

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

What are the three logical operators?

A
logical and ( && )
logical or ( | | )
logical not ( ! )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

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

A

logical and or logical or operator
eg
((5<2) && (2>=3))

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

What is the purpose of a loop?

A

repeat a condition until the loop ends

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

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

A

loop will continue until the condition reaches a specific state or number

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

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

A

running the loop once

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

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

A

before executing the statement

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

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

A

once at the start

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

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

A

before each loop iteration

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

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

A

after each iteration

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

What does the ++ increment operator do?

A

it increments its operand and returns a value

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

How do you iterate through the keys of an object?

A

with a for-in loop

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

Why do we log things to the console?

A

so we can see the output

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

What is a “model”?

A

a representation of something else

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

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

A

html document

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

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

A

data type object in javascript

All of the properties, methods, and events available for manipulating and creating web pages are organized into objects.

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

What is a DOM Tree?

A

an element plus all of its children

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

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

A

getElementsById(‘id’)

querySelector(‘css selector’)

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

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

A

getElementsByClassName(‘class’)

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

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

A

it saves the browser looking through the DOM tree to find the same elements again

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

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

A

so that the html can load before the javascript

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

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

A

it takes a css selector and returns the first matching element

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

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

A

it takes a css selector and returns all that match

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

What is the purpose of events and event handling?

A

create user interactivity

events - things that happen (could be user interactivity)

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

What is a callback function?

A

a function passed as an argument into another function, 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
82
Q

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

A

event object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
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 selected node, you can console log or console dir

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

What is the difference between these two snippets of code?

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

A

the top is a reference to handleClick while the bottom is being executed immediately with no parameters

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

What is the className property of element objects?

A

className getsor sets the value of the class attribute

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

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

A

element.classname and assignment operator

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

What is the textContent property of element objects?

A

represents the text content of the node and its descendents

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

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

A

element.textContent = text content

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

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

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
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. html only has string data type and would need to be converted

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

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

A

our program cannot be changed by the user changing text content

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

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

A

submit event

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

What does the event.preventDefault() method do?

A

prevents the events default behavior

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

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

A

reloads teh page

98
Q

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

A

elements

99
Q

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

A

value

100
Q

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

A

hard to see where it went wrong

101
Q

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

A

if something happens the console will throw an error

102
Q

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

A

no it creates a new element

103
Q

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

A

with the appendchild method

104
Q

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

A

class and value of the class

105
Q

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

A

create the new element, add any text content/attributes, then append it to another element

106
Q

What is the textContent property of an element object for?

A

represents the text content of the node

107
Q

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

A

className property and setAttribute, classlist

108
Q

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

A

it can be reused
it is faster than creating a new one every time
can be updated easily
give name to a process

109
Q

What is the event.target?

A

target property of the event. a reference to the object onto which the event was displached

110
Q

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

A

because of event bubbling

111
Q

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

A

tagname

112
Q

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

A
it takes a css selector
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.
113
Q

How can you remove an element from the DOM?

A

using the remove() method

114
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 an ancestor element

115
Q

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

A

hides that element from the page

116
Q

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

A

it takes a selector string and returns a boolean

117
Q

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

A

getAttribute method

118
Q

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

A

every step

119
Q

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

A

new event handler for every single one

120
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

an if/else statement for each data view

121
Q

What is JSON?

A

JSON is a text-based data format following JavaScript object syntax
useful when you want to transmit data across a network. It needs to be converted to a native JavaScript object when you want to access the data.

122
Q

What are serialization and deserialization?

A

Serialization is a process of converting an Object into stream of bytes so that it can be transferred over a network or stored in a persistent storage.

Deserialization is the exact opposite - Fetch a stream of bytes from network or persistence storage and convert it back to the Object with the same state.

123
Q

Why are serialization and deserialization useful?

A

you can save the state of an object and recreate it when needed

124
Q

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

A

JSON.stringify

125
Q

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

A

JSON.parse

126
Q

How do you store data in localStorage?

A

with the .setitem() method

127
Q

How do you retrieve data from localStorage?

A

the getItem() method

128
Q

What data type can localStorage save in the browser?

A

strings

129
Q

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

A

when the window, the document, and its resources are about to be unloaded.

130
Q

What is a method?

A

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

131
Q

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

A

method call: calculator.add()
method definition: add: function (x, y) {
return x + y;
},

132
Q

Describe method definition syntax (structure).

A
method name : function keyword, (parameters) {
function
}
133
Q

Describe method call syntax (structure).

A

object.method name (parameters)

134
Q

How is a method different from any other function?

A

a method is within an object

135
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can hold data and behavior

136
Q

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

A

abstraction - being able to work with complex things in simple ways
Encapsulation - bundling of data
Inheritance - basing an object or class upon another object or class
Polymorphism - single interface to entities of different types

137
Q

What is “abstraction”?

A

abstraction - being able to work with complex things in simple ways

138
Q

What does API stand for?

A

application programming interface

139
Q

What is the purpose of an API?

A

an application programming interface connects computers or pieces of software to each other

140
Q

What is this in JavaScript?

A

this is an implicit parameter of all JavaScript functions. contains a reference to the object

141
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

142
Q

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

A

call time

143
Q
What does this refer to in the following code snippet?
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
A

nothing

144
Q

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

A

It’s-a-me, Mario!

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

its a me undefined

146
Q

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

A

cant tell, would be nothing

147
Q

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

A

Find where the function is called and look for an object to the left of the dot

148
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal

149
Q

What is a prototype in JavaScript?

A

an object that holds properties or methods

150
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

the methods are defined on a prototype object and the arrays, strings, and numbers borrow those methods

151
Q

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

A

the prototype

152
Q

What does the new operator do?

A

1 Creates a blank, plain JavaScript object.
2 Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
3 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).
4 Returns this if the function doesn’t return an object.

153
Q

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

A

prototype

154
Q

What does the instanceof operator do?

A

he instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.

155
Q

What is a “callback” function?

A

a function passed into another function as an argument

156
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

settimeout, setinterval

157
Q

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

A

setinterval

158
Q

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

A

0

159
Q

What do setTimeout() and setInterval() return?

A

an interval ID that can be used by clearinterval and cleartimeout

160
Q

What is a client?

A

service requesters

161
Q

what is a server

A

providers of a resource or service

162
Q

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

A

get

163
Q

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

A

method, request target, http version

164
Q

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

A

protocol version, status code, status text

165
Q

What are HTTP headers?

A

line of code. The HTTP headers are used to pass additional information between the clients and the server through the request and response header

166
Q

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

A

mdn

167
Q

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

A

no

168
Q

What is AJAX?

A

Ajax is a technique for loading data into part of a page

without having to refresh the entire page

169
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

170
Q

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

A

XMLHttpRequest

171
Q

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

A

the load event (onload)

172
Q

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

A

prototypal inheritance

173
Q

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

A

code in curly braces, function code block

174
Q

What does block scope mean?

A

it refers to the area that a block has jurisdiction

175
Q

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

A

block scope

176
Q

What is the difference between let and const?

A

let is mutable while const is not

177
Q

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

A

The const keyword creates a read-only reference to a value. The readonly reference cannot be reassigned but the value can be change.

178
Q

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

A

if you need the value to change, use let

if you dont nee it to change , use const

179
Q

What is the syntax for writing a template literal?

A

let var = surround string you want in backticks and use ${variable} for the variable you want inserted

180
Q

What is “string interpolation”?

A

when JS automatically replaces variables and expressions with their values

181
Q

What is destructuring, conceptually?

A

taking something apart

182
Q

What is the syntax for Object destructuring?

A

const/let {object property name: variable name} = object

183
Q

What is the syntax for Array destructuring?

A

const/let [variable name, variable name, variable name] = array

184
Q

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

A

which side the array/object name is on

185
Q

What is the syntax for defining an arrow function?

A

let add = (x, y) => x + y;

186
Q

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

A

the result is automatically returned

187
Q

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

A

an arrow function captures the this value of the enclosing context instead of creating its own this context
this is called on definition

188
Q

What is a CLI?

A

command line interface

189
Q

What is a GUI?

A

graphical user interface, interaction through graphical icons

190
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 - looking up manual
cat - combining text files
ls - ensuring that you created the files you intended to
pwd - you can tell  what directory you are currently on
echo -  
touch -  create an empty file
mkdir - create directories
mv -  rename directory
rm -  delete a directory
cp - copy a directory
191
Q

What are the three virtues of a great programmer?

A

laziness, impatience, and hubris

192
Q

What is Node.js?

A

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

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

194
Q

What is a REPL?

A

read eval print loop
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

195
Q

When was Node.js created?

A

2009

196
Q

What back end languages have you heard of?

A

Ruby, PHP, Java, . Net, and Python

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

198
Q

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

A

process keyword

199
Q

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

A

array of strings

200
Q

What is a JavaScript module?

A

a single js file

201
Q

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

A

exports , require , module , __filename , __dirname

202
Q

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

A

console

process

203
Q

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

A

allow exporting of a module to be used somewhere else

204
Q

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

A

const add = require(‘./add’);

205
Q

What is the JavaScript Event Loop?

A

a programming construct or design pattern that waits for and dispatches events or messages in a program.

206
Q

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

A

Blocking is when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes.
all synchronous code is blocking

207
Q

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

A

fs

208
Q

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

A

fs.writefile

209
Q

Are file operations using the fs module synchronous or asynchronous?

A

both

210
Q

What is NPM?

A

npm is a package manager for the JavaScript programming language
website, cli, registry

211
Q

What is a package?

A

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

212
Q

How can you create a package.json with npm?

A

npm init

213
Q

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

A

Packages required by your application in production

npm install name of

214
Q

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

A

npm downloads the dependency
node module gets created
dependency gets put in node-module
library gets added to json

215
Q

How do you add express to your package dependencies?

A

npm install express

216
Q

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

A

listen method

217
Q

How do you mount a middleware with an Express application?

A

app.use

218
Q

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

A

req, res

219
Q

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

A

application/json

220
Q

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

A

parses incoming json, need it when receiving json body messages

221
Q

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

A

to indicate the desired action to be performed for a given resource

222
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS). It is often cited as the most advanced open source database of its kind and is well-liked by the developer community for its robust feature set, standards compliance, and reliability.

Other popular relational databases include MySQL (also free), SQL Server by Microsoft, and Oracle by Oracle Corporation.

223
Q

What are some advantages of learning a relational database?

A

if you are storing related data, then a relational database is probably a good first choice. A quality of many relational databases is that they support good guarantees about data integrity. Relational databases are arguably the most widely used kind of database.

224
Q

What is one way to see if PostgreSQL is running?

A

sudo service postgresql status

225
Q

What is a database schema?

A

collection of tables
A schema defines how the data in a relational database should be organized. In relational databases, you typically have to define your schema up front and the database server will make sure that any data being written to the database conforms to that schema.

226
Q

What is a table?

A

A table is a list of rows each having the same set of attributes. For example, all students in a “students” table could have “firstName”, “lastName”, and “dateOfBirth” attributes

227
Q

What is a row?

A

an entry of data

228
Q

What is Array.prototype.filter useful for?

A

anytime you need to filter an array

229
Q

what is array.map useful for?

A

mutating an entire array based on a transform function

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

231
Q

What is the typeof an ES6 class?

A

function

232
Q

Describe ES6 class syntax.

A

class keyword, name of class, class body, prototype methods

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

234
Q

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

A

function

235
Q
What does this code do?
const wrap = value => () => value;
A
recursion
wrap() returns the function [()=>value]
236
Q

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

A

when it is defined, lexical scope

237
Q

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

A

closures due to lexical scope

238
Q

What does the acronym LIFO mean?

A

last in first out

239
Q

What methods are available on a Stack data structure?

A

pop push peak print

240
Q

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

A

pop off the values in the stack until you reach the one you want