JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store values to be called upon 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

using a keyterm (var, let, const)

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

how do you initialize a variable?

A

using an equal sign

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 (cap and no cap), numbers (cannot start with a number), non keyword (e.g. var), - , .

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

What does it mean by variables are case-sensitive?

A

var Cat and var cat are two separate variables

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

what is the purpose of a string?

A

to store letters/words/phrases values

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

what is the purpose of a number?

A

to store number values

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

what is the purpose of a boolean

A

to store true and false values (values that can only be 1 of the 2)

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

what does the = operator mean in JS?

A

a value is being assigned to something else

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

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

null is user-defined emptiness, it is intentional and has to be assigned by the programmer (intentional emptiness)
undefined can be assigned by JS to create absence (usually not assigned by programmer)

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

so you know which value you are logging and potentially where to find it

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

what are objects used for?

A

used to group similar properties together for ease of calling the values

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

what are object properties?

A

Object properties are variables within an object, usually are related or similar to the other properties within an object.

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

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

A

dot notation and bracket notation
object.property
object[‘property’]

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

what data type is returned from an arithmetic operation?

A

numbers

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

What is string concatenation?

A

addition for string values

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

what purpose does the + operator have in JS?

A

adds two values together

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

What data type is returned from using comparator operators? (greater than, less than, ===)

A

boolean (true/false)

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

what does the += operator do?

A

takes the existing value of a variable, adds another value to it, then assigns the new value back to it.

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

what are objects used for?

A

used for grouping up similar properties with values together for ease of access later

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

What are arrays used for ?

A

creating a numbered list of values, number of items within an array can be modified

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

describe array literal notation

A

[ value, value, value, value]

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

how are arrays different from “plain” objects?

A

arrays have a numbered index, order, and use [ ].

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

what is the length property of an array?

A

counts the number of indexes inside an array.

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

how do you calculate the last index of an array?

A

array[array.length - 1]

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

describe object literal notation

A

{ prop: value, prop: value, prop: value }

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

how do you remove a property from an object

A

using delete operator, followed by the object.property

delete object.property

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

what is a function?

A

reusable block of code that is able to receive different inputs and return different outputs based on those inputs

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

what is an expression?

A

a block of code or work that the computer needs to perform before it can assign it as a value.

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

what are the parts of a function definition?

A

keyword (function), optional function name, optional paramater list, { }, optional return

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

what are the parts of a function call

A
function name( ), argument
function(argument)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What are the differences between a function call and function definition?

A

function call has argument instead of parameter, does not have the function keyword, no function code block.

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

What is the difference between a parameter and argument?

A

parameter is a placeholder for when defining a function, argument is a value that is actually passed through the function when calling the function.

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

Why are function parameters useful?

A

They are a placeholder for values to be passed through a function, let the user of the function know what arguments are allowed in the function

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

What two effects does return have on the function?

A

ends the function and pushes results of the work done inside the function outside so that it can be accessed

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

why do we log things in the console?

A

to check for errors in the code/ debugging

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

what is a method?

A

a method is a function that exists as a key in an object

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

How is a method different from any other function?

A

theyre effectively the same, a method just exists inside an object

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

how do you remove the last element of an array?

A

pop method of the array object

array.pop()

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

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

A

Math.floor() or Math.trunc()

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

How do you generate a random number?

A

Math.rand();

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

How do you delete an element from an array?

A

string.splice(index position to start, number of elements to remove, any elements to add starting from the splice start position)

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

How do you append an element to an array?

A

array.push(element)

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

how do you break a string up into an array

A

string. split(what is being split)

e. g. ‘ ‘ would split it at every space, ‘’ would split at every character

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

how do you capitalize all the letters in a string?

A

string.toUpperCase();

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

Do string methods change the original string? how would you check

A

no, console.log

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

how many string methods are there according to MDN web docs?

A

~30

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

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

A

some functions/methods do not need a return

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

how many array methods are there according to mdn docs?

A

~40

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

what three letter acronym should you always include in your google search about a JS method or CSS property?

A

mdn

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

6 examples of comparison operators

A

greater than, less than, greater than and equal to, less than and equal to, absolutely equal to, equal to (dont use), absolutely not equal to, equal to

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

what is the purpose of an if statement?

A

create conditionals

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

Describe the syntax (structure) of an if statement

A

if keyword, followed by a condition, followed by the if-code block. condition is made up of two operands with an operator sandwiched between

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

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

A

using $$ or || (and / or)

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

What is the purposed of a loop?

A

To run a designated block of code a number of times

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

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

A

It allows for the computer to know when to end the loop (once the condition fails)

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

What does iteration mean in the context of a loop?

A

each run through the loop is a single iteration

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

when does the condition of a while expression for a while loop get evaluated?

A

Before running the code inside the while loop code block.

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

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

A

when the loop is first read by the computer, it will initialize the initialization expression. Only done once, before the first condition expression

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

What is a falsey or truthy value?

A

values that JS coerces into a boolean value when placed in the context of a conditonal statement.

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

What are falsey values?

A

false, undefined, ‘empty string’, “empty string”, 0, -0, NaN, 0n, null, undefined

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

What are nodelists

A

an object created from using querySelectorAll, not a dom element, is a list of dom elements to prevent change to them. it is an array-like object.

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

what does the $ sign mean typically in dom?

A

stylistic choice; if used, all dom elements should be named using a $ in order to separate it from other variables. (should be used for the dom element rather than the content - only attached to values assigned to from query selector and queryselectorall)

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

what is event handling?

A

code that is executed to respond when an event has happened, to “handle” that event ( most events will be user controlled, but some can be controlled by time etc)
something to do in response to an event occurring

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

difference between event listener and handler?

A

event listeners designed to wait for an event to occur, and then invokes a list of functionalities that then occurs when the event occurs, event listeners call the event handler when the event occurs

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

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

A

after the variable is declared, but before the code inside the for loop declaration block is run.

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

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

A

after the for loop code block gets executed, before the condition expression kicks in again

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

what does the ++ increment operator do?

A

increases the variable value by 1

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

how do you iterate through the keys of an object

A

for in loops

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

why do we log things to the console?

A

to make sure our expectations meet our results/ check for bugs in the code

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

What is a ‘model’

A

a representation of something, a smaller version that is equally if not as detailed as the original

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

which document is referred to in the phrase Document Object Model

A

html

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

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

A

the document object refers to the virtual object formed by js to interact with the html/css code

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

What is a DOM Tree

A

a model of dom in a tree structure, allows you to find the relationships between each node/element and therefore how to access each one

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

give two examples of document methods that retrieves a single element from the DOM

A

document.querySelector(), getElementByID()

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

document method that retrieves multiple elements form the DOM at once

A

document.querySelectorAll();

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

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

A

to make it easier to access for later uses instead of having to recall it again everytime

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

why would a script tag need to be placed at the bottom of the HTML element instead of the top?

A

The DOM is created at the instance the script is run, if the script is before the HTML code, nothing will be read. The DOM is loaded in after all the css and html is loaded into the page

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

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

A

it takes a css. selector and returns the first child element of that selector

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

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

A

it takes a css selector as its argument and returns all elements of that type as a nodelist

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

what is the purpose of events and event handling?

A

to allow for user interactivity with the webpage

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

what is a callback functoin?

A

a function that is passed through another function as an argument, and then invoked inside the outer function to complete action or routine

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

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

A

an event object

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

What is the event.target?

A

a reference to the object that was targeted when the event was dispatched

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

what is the difference between
element.addEventListener(‘click’, handleClick)
and
element.addEventListener(‘click’,handleClick())?

A

the second one calls the handleClick function, causing it to execute it immediately - second one waits until the ‘click’ event occurs before calling the function.

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

what is the className property of element objects

A

it is all the values of the class attribute in an html element (the classes refer to css classes). can be set with the className property

96
Q

How do you update the css class attribute of an element using Javascript?

A

using className, classList, or dom-creation setAttribute()

97
Q

What is the textContent property of element objects?

A

it is the user-readable text content in an html element

98
Q

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

A

element.textContent = ‘updated-text’;

99
Q

is the event parameter of an event listener callback always useful? (function inside an eventlistener)

A

no, sometimes the function can be run without any input from the event itself (aside from activating the function call)

100
Q

would this assignment be simpler or more complicated if we didnt use a variable to keep track of the number of clicks?

A

its easier because we’d be able to debug it in the case that it breaks (e.g. buttons classes changes not being applied with click count, color not changing when button classes change)

101
Q

why is storing information about a program in variables better than storing it in the dom?

A

They are more accessible through the console.log

102
Q

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

A

focus event

103
Q

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

A

blur event

104
Q

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

A

input event

105
Q

what event is fired when a user clicks the submit button within a form?

A

submite event

106
Q

what does the event.preventDefault()

A

prevents the event’s default behavior from occurring

107
Q

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

A

does not prevent the default behavior of the form, in the case that theres no action, ends up refreshing the page

108
Q

what property of a form element object contains all of the form’s controls?

A

the elements property

109
Q

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

A

setAttribute()

110
Q

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

A

if something goes wrong or theres a bug in the code, it’s hard to pinpoint the root of the problem

111
Q

what is one advantage of having your console open when writing a javascript program?

A

you can see in real time if your code is creating bugs and therefore solve them or correct them before the code gets too convoluted

112
Q

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

A

no, it only creates the element in the dom, it still needs to be appended into the actual document

113
Q

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

A

you append it with the appendChild() or append methods

114
Q

WHat do you pass as the arguments to the element.setAttribute method?

A

the value you want to set it to (as a string) and the value (as a domstring value)

115
Q

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

A

first you need to create the element, then you need to append it to an element that exists in the document page already

116
Q

What is the textContent property of an object for ?

A

allows you to get or set the user-readable text in an element object

117
Q

what are two ways to set the class attribute of a DOM element?

A

setAttribute, classList.add/remove, nameClass

118
Q

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

A

makes it so that it can be reusable, and helps define the purpose of that segment of code

119
Q

give two examples of media features that you can query in an @media rule

A

min-width and max-width

120
Q

Which HTML meta tag is used in mobile responsive web pages

A

viewport meta tag

121
Q

what is the event.target?

A

it is a dom element object that points to the element that is being targeted by an action

122
Q

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

A

due to dom event delegation (bubbling)

123
Q

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

A

event.target.tagName - returns element type as a string in all caps

124
Q

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

A

it takes a css selector as its argument, returns everything from itself to the nearest ancestor element towards the root with that specified css selector

125
Q

How can you remove an element from the DOM

A

using the remove method of that element (element.remove())

126
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

attach the event listener to the parent element of the elements you want to control, that way any amount of elements added or removed can be affected through the parent element

127
Q

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

A

it hides the element from the viewport

128
Q

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

A

it takes a css selector and returns a boolean

129
Q

How can you retrieve the value of an elements attribute?

A

using the getAttribute() method of the element object

130
Q

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

A

inside/outside loops, to check event listeners are working properly, checking the conditions of loops, any variables being updated

131
Q

If you were to add another tab and view to your HTML, but you didnt use event delegation, how would your JS code be written instead?

A

you’d have to create a new event Listener

132
Q

What is JSON

A

JavaScript Object Notation; it is an interchange data type used to transmit and store data

133
Q

what are serialization and deserialization?

A

serialization converts data into a contiguous series of bytes so it can be stored in memory or sent elsewhere whereas deserialization is turning that series of bytes into readabe data

134
Q

Why are serialization and deserialization useful?

A

Serialization lets you send data out, deserialization makes reading that data easier so that you dont have to parse the serialized data every time you want to access the inner objects

135
Q

How do you serialize data into a JSON string in JavaScript?

A

using the stringify method (JSON.strigify())

136
Q

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

A

using the parse method of the JSON object (JSON.parse())

137
Q

How to you store data in localStorage

A

setItem method (localStorage.setItem()

138
Q

How to you retrieve data from localStorage?

A

using the getItem method (localStorage.getItem())

139
Q

What data type can localStorage save in the browser?

A

JSON string

140
Q

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

A

before the page unloads

141
Q

What is a method?

A

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

142
Q

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

A

a method definition will have the function keyword, followed by the method name and any parameters. the method call will just have just the method name and any arguments

143
Q

Describe method definition syntax

A

name of the method property, followed my a colon to show that you’re assigning it a value. follow it with the function keyword, an optional name (if you want to call it on itself), any parameters, the code block, then a comma if there are any additonal properties after it

144
Q

Describe method call syntax (structure)

A

call the object followed by the property name for that function

145
Q

How is a method different from any other function?

A

you have to call as a property of its object first, it’s not “freestanding” and can be called by itself like a function can

146
Q

What is the defining characteristic of Object Oriented Programming?

A

You can store both properties and methods together (data and behavior)

147
Q

What are the four prinicples of OOP

A

abstraction, encapsulation, inheritance, polymorphism

148
Q

What is abstraction?

A

being able to work with complex things in simple ways e.g. light switch or DOM API

149
Q

What does API stand for?

A

Application Programming Interface

150
Q

What is the purpose of an API

A

to let two computers or programs interact with each other

151
Q

What is “this” in JavaScript

A

it points to the nearest Object “this” is inside of, the window if its not inside another object

152
Q

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

A

This inherently does have a value, it is only given when a function is called

153
Q

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

A

call time

154
Q

What does this refer to in the following code snippet?

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

the window

155
Q

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

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

character.greet();

A

“it’s a me Mario” b/c the this was defined when the method was called

156
Q
given 
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
What is the result of the following code snippet? why?
var hello = character.greet;
hello();
A

‘It’s a me, undefined’ b/c hello is a property of the window object. This now points to the window object, so when it looks for window.firstName, it is unable to find it and returns undefined.

157
Q

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

A

it’ll be nothing because it has no value, it is an implicit parameter, it is only defined at function call, not function/method definition

158
Q

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

A

it’ll be pointing to the object on the left of the . for a method.

159
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype

160
Q

What is a prototype in JavaScript?

A

it is an object or object like structure that descendants of that prototype will inherit properties or methods from

161
Q

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

A

They all have a prototype object that they inherit specific property and methods from

162
Q

IF an object does not have its own property or method by a given key, where does JS look for it?

A

it looks for it in its prototype

163
Q

What does the new operator do?

A
  1. Creates an empty plain JavaScript object
  2. adds a property to the new Object that links to the constructor function’s prototype object
  3. binds newly created object instance as the this context (all references to this in the constructor function now point to the object created in the new op step)
  4. returns this if the function doesnt return an object
164
Q

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

A

prototype

165
Q

What does the instanceof operator do?

A

Checks if the target object has any lineage that includes the prototype property of a specified constructor

166
Q

What is a callback function

A

it is a function that is used as an argument in another function

167
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() and setInterval()

168
Q

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

A

using the setInterval() method

169
Q

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

A

no time delay

170
Q

What do setTimeout() and setInterval() return?

A

a timeout ID to identify the timer created by the method

171
Q

what is a client?

A

Does not usually share resources, but does request content or services from a server

172
Q

What is a server

A

runs one or more server programs that share resources with clients when requested

173
Q

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

A

GET

174
Q

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

A

HTTP method (get, post, put, delete), request target (URL, absolute path), HTTP version (usually 1.1, maybe 2)

175
Q

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

A

version, status code, status message

176
Q

What are HTTP headers?

A

provide additonal information about the body of the response, about the data; metadata

177
Q

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

A

mdn

178
Q

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

A

no

179
Q

What is AJAX?

A

programming practice of building complex dynamic webpages

180
Q

What does the AJAX acronym stand for?

A

Asynchronous Javascript and XML

181
Q

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

A

XMLHttpRequest

182
Q

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

A

Load event

183
Q

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

A

share the same prototype ancestor (eventtarget)

184
Q

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

A

A code block is a snippet of code that is grouped together within curly braces, function code block, condition code block

185
Q

What does block scope mean?

A

Block scope means within the block of code where a variable can be defined

186
Q

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

A

block scoped for both (local)

187
Q

What is the difference between let and const?

A

Const is immutable ( like a string ) and creates a read-only reference to a value, let can be mutated

188
Q

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

A

the variable created by const becomes read-only, but the value the property points to is still mutable (cant reassign a variable created by const, but can change things inside)

189
Q

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

A

Const should be used if the variable will never be reassigned, let allows you to reassign that variable as much as needed

190
Q

What is the syntax for writing a template literal?

A

instead of single quotes or double quotes around the content you want to encapsulate, you use back-ticks ( ` ), any javascript expression is written as ${expression/variable}

191
Q

What is “string interpolation”?

A

String interpolation is where parts of the string are replaced with variable values or expressions

192
Q

What is destructuring, conceptually?

A

taking apart the property/values of an object and assigning them to variables

193
Q

what is the syntax for destructuring for objects?

A

const/let {variable_name: property_name/value you want to assign} = object (object you are obtaining the property’s value from)

194
Q

What is the syntax for destructuring arrays?

A

const/let [var 1, var2, … varX] = array_name
var1 = element at first index
var2 = element at second index
varX = all other elements leftover (due to the spread operator […])

195
Q

How can you tell the difference between destructuring and creating object/array literals?

A

depends on which side the object/array literal notation is on; if the curly braces/ array is on the left, it is destructuring. if it’s on the right side, it’s constructing.

196
Q

what is the syntax for defining an arrow function?

A

let/const/var function_name = paramater or (x, y, …z) or ( ) => expression or { if code is longer than one line}

197
Q

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

A

the expression denoted by the arrow function is implicitly returned

198
Q

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

A

it is determined when the arrow function is defined

199
Q

what is a CLI ?

A

command line interface

200
Q

what is gui

A

graphical user interface

201
Q

One use case for each of the following:

man , cat, ls, pwd, echo, touch, mkdir, mv, rm, cp

A

man - pulls up manual, cat - concatenates the contents of two files together, ls - lists all files and directories within a level of a directory, pwd - prints current file location, touch - updates files, creates them if they are not present, mkdir - makes directory, mv - moves file location, rm - removes file or directory PERMANENTLY, cp - copies file or directory

202
Q

What are the three virtues of a great programmer?

A

Laziness, impatience, and hubris

203
Q

What is node.js

A

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

204
Q

What can node.js be used for?

A

used to build back-end for web-apps, command-line programs, things you want to automate

205
Q

What is REPL?

A

REPL (read-eval-print loop) is an interactive shell that takes in user inputs, executes them, and then returns the result back to the user

206
Q

When was node.js created?

A

May 27, 2009

207
Q

What back-end languages have you heard of?

A

python, PHP, JavaScript, Java, C#

208
Q

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

A

It refers to the Node.js program itself running

209
Q

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

A

console.log(process);

210
Q

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

A

array of strings

211
Q

what is a JavaScript module?

A

an individual JavaScript file is treated as its own separate module

212
Q

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

A

exports, require, module, __dirname, __filename

213
Q

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

A

process, console

214
Q

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

A

Allows for Node.js to access whatever value that is assigned to the exports property in another node.

215
Q

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

A

using the require() function

216
Q

What is the JavaScript event loop

A

a runtime that is specific to JavaScript, allows it to execute code, run and process events, and execute sub-queue tasks ; the thing that waits for the callstack to be cleared before pushing the things in the queue into the call stack

217
Q

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

A

since javascript is a single thread language, when a process takes time, it prevents any other code from executing. non-blocking code would allow for other code to complete in a synchronous fashion.

218
Q

What is a directory?

A

a location to store files

219
Q

What is a relative file path?

A

the location of the file relative to another location/directory

220
Q

What is an absolute file path?

A

the location of the file relative to the root directory

221
Q

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

A

fs

222
Q

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

A

writeFile() method

223
Q

Are file operations using the fs module synchronous or asynchronous?

A

can be either or depending on the operation

224
Q

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

A

GET

225
Q

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

A

HTTP version, request target, http version

226
Q

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

A

HTTP Version, status code, status message

227
Q

What are HTTP headers?

A

additonal metadata about the server request or response

228
Q

Is a body required for a valid HTTP message?

A

no

229
Q

What is NPM?

A

Node packet manager - big software library , website-gui to browse registry, cli - command line client that talks to registry, registry (database)

230
Q

What is a package?

A

file or module of js code that is reusable - a directory of files has at least one file, including a package.json file w/ metadata about the package

231
Q

How can you create a package.json with npm?

A

go to the root of the directory you want to create a package.json in, and then use
‘npm -init’

232
Q

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

A

code you want to use but you didnt create, your code depends on it but you did not create it, using ‘npm install ‘package_name’’
prod dependencies - code that is used to help the code run
dev dependencies - code that doesn’t make it to the final product, it is used striclty for development (e.g. eslinter for

233
Q

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

A

updates the package.json file, creates a node-modules folder (if it doesnt already exist ) and installs the package (in the directory you put it in)

234
Q

How do you add express to your package dependencies?

A

npm install express

235
Q

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

A

listen method

236
Q

How do you mount a middleware with an Express application?

A

use method of the app object

237
Q

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

A

req and res