JavaScript Flashcards

1
Q

what is the purpose of a variable?

A

to store information to be referenced to

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

How do you declare a variable?

A

variable keyword and variable name

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

with an = sign (assignment operator) and a variable value after it

var nameOfVar = value (string, number, boolean data type)

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, or underscore

but a number cannot be the first character

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

when you call the variable name, you have to call it by its exact value or the computer won’t recognize it

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 a collection of characters (could be a letter, number, or a backslash)

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 numbers

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 determine which code should run?

to store true/false value

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

variable assignment

provide variable 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

call the variable name, assignment operator, and the new variable 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 an assigned value– it means there is nothing in the variable

undefined means a variable has been declared but not defined with values yet

as a developer, you never want to assign a variable as undefined

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 can tell which variables are being logged and in what order– this is especially helpful when you need to 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

Number, String, Boolean, Null, Undefined

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 purpose(s) does the + plus operator serve in JavaScript?

A

to concatenate strings or add numbers

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

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

A

adds/concatnates value from the right to the left variable

the current value of that variable, bring in some value, add that on to the current value, and the result of that is the new value

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

What is string concatenation?

A

the process of joining multiple strings together

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

What are objects used for?

A

used to group together a set of variables and functions to create a model

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

What are object properties?

A

a variable– properties 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

its an array of key-value pairs with a colon separating the keys and values and a comma after every key-value pair (except for the last)

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

you use the delete keyword followed by the object name and the property name

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

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

A

dot notation or bracket notation

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

What are object methods?

A

a function– methods represent tasks that are associated with the object

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

What are arrays used for?

A

arrays are used to store 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
26
Q

Describe array literal notation.

A

values are assigned to the array inside a pair of square brackets and each value is separated by a comma

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

How are arrays different from “plain” objects?

A

like objects, arrays hold a key value pairs, but with arrays, the key for each value is its index number

array is a list of items and objects are collections of individual items?

objects are a collection of data with individual name of properties with no set order and arrays are in a set order and are a list of items arrays hold data that are similar

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

What is the length property of an array?

A

the amount of items in the array

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

How do you calculate the last index of an array?

A

array length minus 1

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

What is a function in JavaScript?

A

it’s essentially a block of code or statement you write that performs a task or calculates a value and it can be used multiple times

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

Describe the parts of a function definition.

A
  • function keyword
  • function name
  • parentheses with parameters inside
  • curly braces
  • inside curly braces, you have the function code block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Describe the parts of a function call.

A
  • name of the function
  • open and close parentheses
  • inside the parentheses, you have arguments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

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

A

a function definition is a lot longer than a function call with all the tasks it needs to perform, however, a function definition alone is not going to perform any action unless the function call calls the function

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 an argument?

A

parameter is essentially a placeholder for when we call the function and pass in an argument

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

Why are function parameters useful?

A

parameters allow us to pass instructions into a function

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

2) prevents any more code in the function code block from being run

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

it informs what the code is doing and alerts you if there’s an issue– so logging things to the console is great for debugging or when you don’t understand code block

to see what the code we’re writing is doing

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 which is a property of an object

a function stored in a 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

a method is attached to an object

in order to call a method, you have to attach the function name to their object using dot notation, and to call a regular function, you use its name

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

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

floor() method

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() (from 0 - .9999)

what’s the purpose?
treat it as a percentage, that will get multiplied with your range value
random acts as a decimal

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

splice() method

arguments: (index, how many elements to remove)

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

push()

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

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

string methods do not change your original string

you can check by logging your value to the console

strings are immutable, you cannot change the original string

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

a lot

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

like the push method, you dont need to know the length of it

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

a lot

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, official docs, it has all the documents you need

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

Give 6 examples of comparison operators.

A

less than, greater than, less than or equal to, greater than or equal to, strictly equal, strictly not equal

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

What is the purpose of an if statement?

A

to test conditions, if the condition is true, the subsequent code statement runs

to make decicions

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

Is else required in order to use an if statement?

A

no

only use else if you need to

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

Describe the syntax (structure) of an if statement.

A
if keyword 
open and close parenthesis
a condition inside the parentheses
open and curly braces
code to be executed inside the curly braces if condition is true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

What are the three logical operators?

A

logical and operator
logical or operator
logical not operator

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

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

A

expression one on one side expression two on the other side and a logical operator in between follow by another pair of parenthesis to wrap the two expressions

by using logical operaters

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

What is the purpose of a loop?

A

to repeat similar code a number of times

to repeat code and when to stop repreating code

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

it lets the loop statement know whether it should be executed

we can think of condition as a break, if its truthy we continue if its falsy we stop

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

repeat?

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

first

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

first, before anything, and only 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

second, your condition run betore each iteration

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

last, after the code block has ran? it is run after the code block

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 its operand, increments the variable by one

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

How do you iterate through the keys of an object?

A

for in loop

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

Why do we log things to the console?

A

to see what the code is doing and to understand what is going on

70
Q

What is a “model”?

A

a set of rules that define what type of content each element is allowed to have??

a dom tree?

a representation of something else

71
Q

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

A

HTML

72
Q

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

A

object is referring to the data type?

73
Q

What is a DOM Tree?

A

the dom tree is an element plus all of its containing elements including the child elements, etc

the dom tree is an element holding all other elements

a DOM tree is a tree of elements with the document node at the top (root) which points to the element node which in turn points to its child element nodes (head and body) and so on

from each of those elements, you can navigate the DOM structure and more to different nodes

74
Q

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

A

querySelector() and getElementById()

75
Q

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

A

querySelectorAll()

76
Q

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

A

to make it easier to access the value later on

77
Q

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

A

console.dir() – displays an interactive list of the properties of the specified JavaScript object

the output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects

use it when you want to see the data of the dom elements?

78
Q

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

A

it gives the HTML time to load before any of the JS loads

which can prevent errors, and speed up website response time

79
Q

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

A

takes in a selector that describes the element your querying for and returns the HTML element object representing the first element of the specified selectors

80
Q

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

A

takes in a selector and return a node list (an object of a collection of nodes) of the document’s elements that match the specified group of selectors

81
Q

Why do we log things to the console?

A

to see what the code is doing

82
Q

What is the purpose of events and event handling?

A

events and event handling trigger the code when specific events occur from the user (such as when the user clicks on a button)

without events and event handle, your website is static (not changing)

83
Q

What do [] square brackets mean in function and method syntax documentation?

A

it means that that piece is OPTIONAL

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 into another function as an argument which is then invoked inside the outer function to complete some kind of routine or action

86
Q

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

A

event object (such as event.target, event.pageX, event.pageY..)

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

you can check on MDN for answer

it returns the node/element that was targeted by the function

get the element that triggered a specific event

the target event property returns the element that triggered the event

the html element that triggered the event

88
Q

What is the difference between these two snippets of code?

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

A

the parentheses are omitted where the function is called because they would indicate that the function should run as the page loads (rather than when the event fires)

the first code– handleClick function will run when ‘click’ occur vs the second code–handleClick() will run right away

89
Q

What is the className property of element objects?

A

a string value that contain a list of all the classes that applied to that element

90
Q

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

A

assignment operator?

you’d need the dom element of that class?

when you are updating a className, you are updating the className attribute?

91
Q

What is the className property of the element objects?

A

it gets and sets the value of the class attribute of the specified element

92
Q

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

A

no, not always usefull

93
Q

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

A

no, not always useful

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 complicated, we’d have to dgo back to the dom to retrieve the counter number and reassignn it to the textContent

95
Q

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

A

focus event

96
Q

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

A

blur event

97
Q

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

A

input event

change event is similar, but stick to input event for now

98
Q

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

A

submit event

99
Q

What does the event.preventDefault() method do?

A

tells the browser that if the event does not get explicitly handled, its default action should not be taken as it normally would be

prevent default method allows you to prevent the default behavior from occurring on an event

ex: when a link (anchor tag) is involved, the behavior default is to navigate to that new URL, but using the method, we’re able to stop the browser from redirecting the page

100
Q

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

A

the browser would reload the page and submit the data for you and refreshes the page (this is if the form does not have an action attribute (as if action=”insert-link”), it’ll just reload the page)

(with the method, if there’s an action attribute within our form element, it will prevent the browser to send the data over to that link)

101
Q

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

A

elements property

HTMLFormElement.elements returns an HTMLFormControlsCollection listing all the form controls contained in the form element

you can obtain just the number of form controls using the length property

you can access a particular form control in the returned collection by using either an index or the element’s name or id
(you should just use the name attribute!!)

102
Q

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

A

value property

103
Q

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

A

it’ll be hard to find your error(s) throughout the code

104
Q

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

A

the console will let you know if there’s an error

105
Q

What does HTMLFormElement.reset() method do?

A

this method restores a form element’s default values

it does the same thing as clicking the form’s reset button

106
Q

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

A

this is due to event bubbling– when you hover over a link, for example, javascript can trigger events on the a (anchor tag) element and also any elements the a (anchor tag) element sits inside

107
Q

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

A

event.target.tagName or event.target.nodeName

108
Q

How can you remove an element from the DOM?

A

using the remove() method

syntax: node.remove()

110
Q

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

A

takes a selector as an argument and returns itself or the cloest matching ancestor

this method traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor

110
Q

What is the event.target?

A

it returns the node/element that was targeted by the function

MDN: target property of the Event interface is a reference to the object onto which the event was dispatched

MDN: Event interface represents an event which takes place in the DOM. An event can be triggered by te user’s action e.g. clicking the mouse button

111
Q

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

A

it turns off the display of an element so that it has no effect on the layout as if the element did not exist

112
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

113
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

you add the event listener to its parent element

so using event delegation

114
Q

What is the event.target?

A

traget property of the event object holds the dom element that the user interact with to trigger that element
element that interacted with (most directly) that trigger that event
it doesn’t matter where you put the event.target you put on, event target will only trigger the element that get interacted with

115
Q

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

A

display: none, position: absolute and fixed – the document act like these dont exist except for display nis being removed from the documne tlfow

116
Q

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

A

takes a selector 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

afterafter 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

you would have add an event listener to every tab

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

you would have to write an if statement for each tab

121
Q

What is JSON?

A

a text-based data format following on JS object syntax

it’s useful when you want to transmit data across a network

122
Q

What are serialization and deserialization?

A

serialization is the process of turning an object in memory into a stream of bytes (turning object, array, value to json string?)

vs

deserialization is the reverse of serialization by turning a stream of bytes into an object in memory (turning json string back into object, value?)

123
Q

Why are serialization and deserialization useful?

A

serialization is useful for sending data over the network

deserialization is useful for recreating/retrieving the object in the same state as when you serialized it

people often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process, taking data structured from some format, and rebuilding it into an object

today, the most popular data format for serializing data is JSON.

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 the localStorage property?

A

setItem() method

localStorage.setItem()

127
Q

How do you retrieve data from the localStorage property?

A

getItem() method

localStore.getItem()

128
Q

What data type can localStorage save in the browser?

A

string

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

refreshing your page, closing browser, navigating to another link would trigger beforeunload

130
Q

What is a method?

A

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

2 kinds of methods:

1) Instance Methods – built in tasks performed by an object instance
2) Static Methods – tasks that are called directly on an object constructor

131
Q

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

A

a method definition is an function that is being defined in an object with the function code block vs a method call is an object function that is being called with ()

132
Q

Describe method definition syntax (structure).

A

property name describing the following function follow by a colon then the function keyword with open and close parentheses (), with optional parameters inside of the (), follow by an open curly brace, and the function code block, then a closing curly brace

133
Q

Describe method call syntax (structure).

A

object name follow by the object’s property and a ()

134
Q

How is a method different from any other function?

A

a method has to be declared inside of an object

methods are just normal function

a function in a property

method can referenced the object they’re inside of

135
Q

What is the defining characteristic of Object-Oriented Programming?

A

OOP can contain both data (properties) and behaviors (methods)

instead of having to pass each data that you would need as arguments, you would have all of this data inside the function and the function can access all of these data (where you behaviors is stored)

136
Q

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

A

abstraction, encapsulation, inheritance, polymorphism

137
Q

What is “abstraction”?

A

according to MDN, abstraction is a way to reduce complexity and allow efficient design and implementation in complex software systems

it hides the technical complexity of systems behind simpler APIs

138
Q

What does API stand for?

A

Application Programming Interface

allows programs to interact with each other in an abstract way

139
Q

What is the purpose of an API?

A

give programmers a way to interact with a system in a simplified, consistent fashion (which is abstraction)

140
Q

What is “this” in JavaScript?

A

“this” is an implicit parameter of all JS functions

by default, “this” will be the global “window” object

syntax: the value of “this” can be recognized as “the object to the left of the dot” when the function is called (as a method)

the value of “this” is determined at call time

141
Q

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

A

it means that it is available in a function’s code block even though it was never included in the function’s parameter list or declared as a variable

implicit parameter is a value within each function without having to declare it yourself

142
Q

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

A

the value of “this” is determined at call time

143
Q

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

A

you can’t

144
Q

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

A

the value of this can be recognized as “the object to the left of the dot” when the function is called (as a method)

145
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based inheritance

146
Q

What is a prototype in JavaScript?

A

a JS prototype is simply an object that contains properties and methods that can be used by other objects

147
Q

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

A

we use the method that are defined on the prototype object

it’s the __proto__ property attached to each object (object, array..) and the proto property has a list of methods

if it doesn’t find the method, it returns an error

148
Q

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

A

look at its prototype

149
Q

What does the new operator do?

A

let us create a version/ an instance to use of one type of thing

IMPT: your constuctor function should never return a statement, “This” is already returned implicitly because we used a new operator

150
Q

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

A

prototype property

prototype property should only be used on constructor functions

151
Q

What does the instanceof operator do?

A

it will check if the object on the right of the operator is a prototype of the object on the left of the operator

152
Q

What is a “callback” function?

A

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

ex:
function greeting(name) {
alert(‘Hello ‘ + name);
}

function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);

this is an example of a synchronous callback, as it is executed immediately.

153
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

by using setTimeOut function

it allows us to call another function and a time determined by us

154
Q

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

A

setInternal function

155
Q

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

A

0s

156
Q

What do setTimeout() and setInterval() return?

A

a timer id

they both pull from the same timer id (so they wont overlap?)

157
Q

What is AJAX?

A

(USE DEFINITION IN BOOK)

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

allows you to request data from a server and load it without having to refresh the entire page

the data is often sent in JSON format

158
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

159
Q

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

A

XMLHttpRequest object

160
Q

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

A

load event?

161
Q

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

A

because XMLHttpRequest is an object, therefore, it has access to the AddEventListener() method?

due to inheritance, they both have EventTarget.prototype in their prototype chains

162
Q

Why do we use the XMLHttpRequest object?

A

we use this it to issue http requests in order to exchange data between the web site and a server

163
Q

What is Array.prototype.filter useful for?

A

useful for filtering out the values you don’t want in an array and store it in a new array

164
Q

What is Array.prototype.map useful for?

A

useful for looping over every element in an array and returning a new array

165
Q

What is Array.prototype.reduce useful for?

A

when you want an accumulation of/combined an array resulting in a single output value (and the return doesn’t have to be an array)

to take a list of things and collapse it down

166
Q

What is “syntactic sugar”?

A

syntax that is designed to make things easier to read and write

167
Q

What is the typeof an ES6 class?

A

function

168
Q

Describe ES6 class syntax.

A
  • class keyword
  • name of class in with the first letter being capitalized
  • a pair of curly braces (this is call the body of the class)
  • within it, a constructor function
  • some methods definition
    (constructor function is where you can initialize the properties of an instance)
169
Q

What is “refactoring”?

A

the process of restructuring computer code without changing or adding to its external behavior and functionality

key thing: behavior of the system doesn’t change

170
Q

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

A

when it is defined

171
Q

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

A

closures

172
Q

✧ what is a closure?

A

combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)

closure gives you access to an outer function’s scope from an inner function

in js, closures are created every time a function is created, at function creation time