JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data that can later be used when called upon.
create permanence in data

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

How do you declare a variable?

A

var variableName

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

variableName = value;

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 (can’t start the variable name)
underscore
dollar sign

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

fullName and FullName are two different variables

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

What is the purpose of a string?

A

used when working with any kind of text
a set of characters in a row that javascript won’t care about

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

mathematical operations

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

hold true/false data types
helpful when determining which part of a script should run

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 operator
stores 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

variableName = 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

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. (automatic assignment from the browser)

null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. (null only exists because its been ASSIGNED–> purposeful)

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 what data you’re looking at.
Sometimes, it’s helpful to put more than one console.log() in your code to help you debug.

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

Give five examples of JavaScript primitives.

A

string
number
boolean
undefined
null

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

What data type is returned by an arithmetic operation?

A

numbers

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

What is string concatenation?

A

adding two strings together

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
string 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

The addition assignment operator (+=) adds the value of the right operand to a variable 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

objects group together a set of variables and functions that are related to each other

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

What are object properties?

A

variables that are part of objects. They 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

you create an object by declaring the variable and assigning its properties and their corresponding values inside of curly brackets or instead use empty curly brackets and add properties later
ex)
var hotel = {
name: ‘Quay’,
rooms: 40,
booked: 25,
}

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.property;

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.propertyName = propertyValue;

square bracket notation
object[‘propertyName’] = propertyValue;

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

What are arrays used for?

A

group similar data types together by storing values in a list

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

Describe array literal notation.

A

var arrayName = [‘item 1’, item2, ‘item 3’, ‘item 4’, item5];

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 each value is its index number (starting at 0)
Don’t have individually named pieces of data, but rather are numerically indexed.
You can determine the number of items in an array (length) but not in a plain object.
Use a method (push) to add stuff to an array, use dot notation or bracket notation with assignment operator to add stuff to a plain object.
Arrays have an order, objects do not

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

arrayName.length

returns the number of items stored in the array

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

How do you calculate the last index of an array?

A

subtract the length of the array by 1
lastIndex = arrayName.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 block of code that gives step by step instructions to accomplish a specific task

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

// [1] [2] [3]
function example(parameter1, parameter2, parameter3, …) { // [4]
// …more JavaScript code…
// [5]
return;
} // [6]

  1. The function keyword to begin the creation of a new function.
  2. An optional name. (Our function’s name is sayHello.)
  3. A comma-separated list of zero or more parameters, surrounded by () parentheses. (Our sayHello function doesn’t have any parameters.)
  4. The start of the function’s code block, as indicated by an { opening curly brace.
  5. An optional return statement. (Our sayHello function doesn’t have a return statement.)
    The end of the function’s code block, as indicated by a } closing curly brace.
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

// [1] [2]
example(arg1, arg2, arg3);

  1. The function’s name. Again, our function’s name is sayHello.
  2. A comma-separated list of zero or more arguments surrounded by () parentheses.
    Our sayHello function does not take any arguments.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

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

A

a function definition contains the steps on what to do with the data (function code block) (parameter)
the function call invokes the function and passes through the data that’s to be worked on (argument)

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

parameter –> placeholder (function definition)
argument –> actual data (function call)

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

Why are function parameters useful?

A

give us the ability to have mutability in what occurs when we call a function (diff parameters allow for the return of different values)

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

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

A
  1. Causes the function to produce a value we can use in our program.
  2. Prevents any more code in the function’s code block from being run.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What is a method?

A

A function that’s assigned to the property of an object

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

Why do we log things to the console?

A

So we can check our code along the way to make sure it’s doing what it’s supposed to do. helps with 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 stored in the property of 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

located within an object
called with the 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 from an array?

A

pop() method
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()

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

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

array.pop() removes last element from the array
array.shift() removes first element of the array
array.splice() removes indicated item(s) from the array

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() appends an element to the end of the array

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

element.split()

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

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

A

No, strings are immutable

Use console.log on the original variable

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

Roughly how many string methods are there according to the MDN Web docs?

A

50

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

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

A

no

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

Give 6 examples of comparison operators.

A

=== strictly equals to
!== strictly is not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to

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

What data type do comparison expressions evaluate to?

A

boolean (true / false)

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

What is the purpose of an if statement?

A

to set up a condition to compare to. If the condition evaluates to true, any statements in the subsequent code block are executed

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

Is else required in order to use an if statement?

A

nope

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

Describe the syntax (structure) of an if statement.

A

keyword + condition + opening curly brace + code to execute if value is true + closing curly brace
if (score >=50) { congratulate(); }

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

What are the three logical operators?

A

&& and
|| or
! not (inverts boolean value)

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

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

A

Use the logical and operator (&&)

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

What is the purpose of a loop?

A

offer the ability to repeat functionality

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

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

A

Evaluate a condition to determine whether or not the loop should run

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

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

A

one time that the loop code block gets run

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

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

A

before each iteration of the code block executes

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

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

A

Before anything runs (just once)

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

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

A

After initialization on the first iteration
before the loops code block and after the final expression

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

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

A

after the code block runs, before the next iteration

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

What does the ++ increment operator do?

A

adds one to the counter variable and saves it to that variable

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

What is a “model”?

A

A representation of something
a copy of the webpage loaded in the browser

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

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

A

The HTML code / the webpage that’s loaded in the browser

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

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

A

The node objects within the HTML code/ webpage

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

What is a DOM Tree?

A

Is a kind of tree whose nodes represent an HTML document’s contents.
All the necessary info to give the characteristics of a single element

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

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

A

document.querySelector()
document.getElementById()

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

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

A

document.querySelectorAll()

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

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

A

If your script needs to use the same element(s) more than once

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

What console method allows you to inspect the properties of a DOM element object?

A

console.dir()

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

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

A

The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.

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

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

A

Argument: A CSS selector as a string
Returns: the first matching element

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

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

A

Argument: a CSS Selector as a string
Returns: All matching elements in a node list

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

What are the different nodes of the DOM tree?

A

Document node
Element nodes (ex: h1, p, h2, li, etc)
Attribute nodes (part of the attribute node that carries them, not a child)
Text nodes (cannot have children)

80
Q

What is the DOM?

A

A javascript object that’s modeling the HTML documents objects

81
Q

What is a node list

A

an array-like object that can’t be changed/messed with

82
Q

What is the purpose of events and event handling?

A

Events – be aware when a certain action happens
event handling– allows us as the developer to do something when the event happens.
interactivity

83
Q

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

A

no

84
Q

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

A

.addEventListener()

85
Q

What is a callback function?

A

A function passed as an argument to another function

86
Q

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

A

the event object -

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 place where the event originated from.
console.log(object.event) + check the MDN.

88
Q

What is the difference between these two snippets of code?
1. element.addEventListener(‘click’, handleClick)
2. element.addEventListener(‘click’, handleClick())

A
  1. Calls the function when the click event happens
  2. The function will be called when the code is run (probably when the page loads)
89
Q

Do event handler functions return a value?

A

No

90
Q

What is the className property of element objects?

A

Contains the current value of the class attribute on that element

91
Q

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

A

Use the className property to assign a new class to the element object you want to change
elementObject.className = newClass

92
Q

What is the textContent property of element objects?

A

A property that contains the text content of a DOM element

93
Q

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

A

No

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

95
Q

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

A

You want the data readily accessible in the language you’re writing

96
Q

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

A

Use the textContent property to assign a new class to the element object you want to change
elementObject.textContent = newText

97
Q

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

A

focus function
focus ()

98
Q

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

A

Blur function
blur()

99
Q

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

A

input

100
Q

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

A

submit

101
Q

What does the event.preventDefault() method do?

A

Prevents the default for any event that would’ve been take
(Default event = what the browser is preconfigured to do)

102
Q

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

A

elements
document.forms.elements

103
Q

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

A

value
document.forms.elements.value

104
Q

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

A

If you run into an error, it’s hard to identify where that error originated

105
Q

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

A

It reloads the page and sends the information back to the page, which is useless (because we don’t specify an action in the HTML code).
So, we always use event.preventDefault() with submitting forms

106
Q

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

A

Nope.

107
Q

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

A

appendChild method
parent.appendChild(child)

108
Q

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

A

the attribute type and value as strings or variables
ex) setAttribute(name, value)

109
Q

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

A
  1. Create the element
  2. Configure the element
  3. Append the element to the page at the parent node (the parent node needs to be queried first)
110
Q

What is the textContent property of an element object for?

A

To add text content to the element that you’re creating

111
Q

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

A
  1. You can reuse it in multiple places
  2. You can use it with different sets of data
112
Q

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

A
  1. setAttribute (‘class’, value)
  2. setClassName()
113
Q

What is the event.target?

A

A property on the event object that stores a reference to the DOM element that the event fired on

114
Q

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

A

event bubbling

115
Q

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

A

tagName

For example, if the element is an <img></img>, its tagName property is “IMG”

For DOM trees which represent HTML documents, the returned tag name is always in the canonical upper-case form. For example, tagName called on a <div> element returns “DIV”.</div>

116
Q

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

A

The argument is the CSS selector
The closest ancestor element
(opposite of query selector)

117
Q

How can you remove an element from the DOM?

A

Call the remove method on the object of the Dom element that you want to remove
element.remove()

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

119
Q

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

A

It’s hidden from view / removed from the document flow

120
Q

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

A

argument: A css selector as a string
returns: boolean

121
Q

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

A

getAttribute() method
argument is a string of the type of attribute we want to retrieve

122
Q

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

A

Every step where your code is doing something/making a change

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

Use individual event listeners for each tab

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

A lot of if statements

125
Q

What is JSON?

A

Javascript Object notation
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax.
JSON is an extremely common data interchange format used to send and store information in computer systems.

126
Q

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a string representation so that it can be stored in memory. All of the data is one contiguous stream (stream of bytes)

Deserialization is the reverse process: turning a stream of bytes into an object in memory. Bringing back the complexity of how the data is stored

127
Q

Why are serialization and deserialization useful?

A

Let’s you move data from one place to another (storing and transmitting data)
Deserialized data is easy to work with

128
Q

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

A

JSON.stringify (data)

129
Q

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

A

JSON.parse(data)

130
Q

How do you store data in localStorage?

A

localStorage.setItem(keyName, keyValue)

131
Q

How do you retrieve data from localStorage?

A

localStorage.getItem(KeyName)

132
Q

How do you retrieve data from localStorage?

A

strings

133
Q

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

A

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point.

134
Q

What is a method?

A

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

135
Q

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

A

Method definition has a function code block and is assigned to a property (:), the function keyword

Method call passes the arguments.
object.method (argument(s))

136
Q

Describe method definition syntax (structure).

A

object {
method: function() {
code block}

object
method name
function keyword and optional name (most often anonymous)
parameters, if there are any
function code block

137
Q

Describe method call syntax (structure).

A

// [1] [2] [3]
object.method(arg1, arg2, arg3);

  1. The object
  2. The method’s name.
  3. A comma-separated list of zero or more arguments surrounded by () parentheses.
138
Q

How is a method different from any other function?

A

It’s the property of an object

139
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

140
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

141
Q

What does API stand for?

A

application programming interface (API)

142
Q

What is the purpose of an API?

A

The purpose of every software API is to give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction.

143
Q

What is “abstraction”?

A

Being able to work with (possibly) complex things in simple ways.

144
Q

What is this in JavaScript?

A

This is an implicit parameter whose value is determined when the function is called, not when it is defined.

145
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.
It’s a value that’s given to each function–it’s’ always present

146
Q

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

A

Call time

147
Q

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

A

nothing (the function hasn’t been called yet)

148
Q

Given the below character object, what is the result of the following code snippet? Why?
character.greet();

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

A

It’s a-me, Mario!

this refers to the character object. character.firstName = Mario

149
Q

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

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

A

It’s a-me, undefined!

this is referring to the default Window object. window doesn’t have a property named firstName

150
Q

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

A

We wouldn’t know because it’s value is assigned upon function call
Parameters are placeholders for future values

151
Q

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

A

Whatever is to the left of the dot

152
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance. – JavaScript objects give certain behaviors (methods) or data (properties) to other objects.

153
Q

What is a prototype in JavaScript?

A

Simply an object that contains properties and (predominantly) methods that can be used by other objects.

154
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

prototypal inheritance

155
Q

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

A

on its prototype

156
Q

What does the new operator do?

A

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
1. Makes an empty object
2. Takes the prototype property from the function and adds it to the new property
3. Runs the function block and makes the value of that new object the value of this
4. It returns the object if no other return is specified

157
Q

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

A

prototype

158
Q

What does the instanceof operator do?

A

The instanceof operator tests the presence of constructor.prototype in object’s prototype chain. This usually means object was constructed with constructor.

obj instanceof class/constructor function

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

160
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()

161
Q

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

A

setInterval()

162
Q

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

A

0 - gets put in the queue immediately

163
Q

What do setTimeout() and setInterval() return?

A

timeout id and Interval id, respectively

164
Q

What is AJAX?

A

A technique for loading data into part of a page without having to refresh the entire page.

165
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

166
Q

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

A

XMLHttpRequest (xhr)

167
Q

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

A

load

168
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 are objects that can receive events
They share a prototype

169
Q

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

A

A group of statements of code to be executed together. Usually contained within curly braces
function code block
conditional (if statement) code block
loop code block

170
Q

What does block scope mean?

A

the value of the variable is dependent/available based on the block of code its located within.

A block scoped variable means that the variable defined within a block will not be accessible from outside the block. A block can reside inside a function, and a block scoped variable will not be available outside the block even if the block is inside a function.

171
Q

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

A

block-scope

172
Q

What is the difference between let and const?

A

block-scoped variables declared by the const keyword can’t be reassigned. read-only reference

The variables declared by the let keyword are mutable. It means that you can change their values anytime you want

173
Q

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

A

The actual value to which the const variable reference is mutable.

174
Q

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

A

If the variable is being reassigned, use let. If it’s not, use const

175
Q

What is the syntax for writing a template literal?

A

you create a template literal by wrapping your text in backticks (`)

let simple = This is a template literal;

176
Q

What is “string interpolation”?

A

Embedding variables and expressions in a string. The JavaScript engine will automatically replace these variables and expressions with their values.

${variable_name}

177
Q

What is destructuring, conceptually?

A

Taking property values or array objects and taking them from their respective objects and arrays and assigning them to a variable

178
Q

What is the syntax for Object destructuring?

A

let { property1: variable1, property2: variable2 } = object;

If the variables have the same names as the properties of the object, you can make the code more concise as follows:
let { firstName, lastName } = person;

179
Q

What is the syntax for Array destructuring?

A

const [first, second, third ] = theArray

180
Q

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

A

Look at what’s on the left and right of the assigment operator
if the variable name that holds the object or array is on the right, it’s destructuring. If it’s on the left, its creating

181
Q

What is the syntax for defining an arrow function?

A

(param 1, param2) => { statements }

don’t need the brackets if the codeblock is multiline
if it’s multiline, a return statement is required

param => expression;

() => exp;

182
Q

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

A

The function body gets evaluated as an expression and the result of the expression is implicitly returned

183
Q

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

A

Arrow functions have lexical this, meaning the value of this is determined by the surrounding scope (the lexical environment).

184
Q

What are the three states a Promise can be in?

A

Pending, fulfilled, rejected

can’t change state once it’s fulfilled or rejected

185
Q

How do you handle the fulfillment of a Promise?

A

then () method

pass a callback function that handles the successful promise

186
Q

How do you handle the rejection of a Promise?

A

catch()

187
Q

What is Array.prototype.filter useful for?

A

to extract certain kinds of data form a list

188
Q

What is Array.prototype.map useful for?

A

Creates a new array populated with the results of calling a provided function on every element in the calling array.

189
Q

What is Array.prototype.reduce useful for?

A

executes a user-supplied “reducer” callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

JS general purpose aggregate function

190
Q

What is “syntactic sugar”?

A

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.
Syntactic sugar is usually a shorthand for a common operation that could also be expressed in an alternate, more verbose, form:

191
Q

What is the typeof an ES6 class?

A

function

192
Q

Describe ES6 class syntax.

A

class keyword Person {
constructor (param1, param2, ….rest) {
this.something= ‘a thing’
}
another method ()
return value
}
}

193
Q

What is “refactoring”?

A

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.

194
Q

How are ES Modules different from CommonJS modules?

A

CommonJS Modules:
The dominant implementation of this standard is in Node.js (Node.js modules
have a few features that go beyond CommonJS). Characteristics:
Compact syntax
Designed for synchronous loading
Main use: server

Asynchronous Module Definition (AMD):
The most popular implementation of this standard is RequireJS.
Characteristics:
Slightly more complicated syntax, enabling AMD to work without eval()
(or a compilation step).
Designed for asynchronous loading
Main use: browsers

195
Q

What kind of modules can Webpack support?

A

ECMA Script Modules, Common Modules, and AMD modules

196
Q

What is the purpose of state in React?

A

Keep track of values that change over time

Think of it as a data model for a component

197
Q

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

A

provide a listener when the element is initially rendered.