JAVASCRIPT Flashcards

1
Q

What is the purpose of variables?

A

A script will have to temporarily store the bits of information it needs to do its job. It can store this data in variables.
Computers require more information than you think.

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

How do youdeclarea variable?

A

You need the variable keyword & 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 the variable name, you need the assignment operator and variable 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

Variable names can only contain letters, numbers, underscores, or dollar signs.
Variable name cannot start with a number.

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

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

A

Capitalized letters vs lowercase letters are not the same value, meaning they make a difference and are “case sensitive”.

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

What is the purpose of a string?

A

Strings are made so that Javascript won’t read it as a code.

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

Tasks that involve counting or calculating sums, numeric 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

They are 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

It is the assignment operator. Assigns right operand value to left operand.

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

Re-write the new value on the right operand and declare it again.
The “var” keyword isn’t necessary for that second time.

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

What is the difference betweennullandundefined?

A

Null: It is the intentional absence of the value.
Null can’t be determined by Javascript.
Undefined: It meansthe value does not exist in the compiler.
Undefined can be determined by javascript.

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 each value represents.

Easier for other people on your team who are also working on the same file.

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

A number data type.

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

What is string concatenation?

A

Joining together two or more strings to create one string, which is the string concatenation.

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

It can either add numbers, or join strings together like previous question.
It can also join variables together.

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

A boolean data type.

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

That operator adds the value of the right operand to a variable and assigns the result to the same variable on the left (this variable on the left will have a new value).

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

What are objects used for?

A

To keep a collection of related data, of primitive or reference types, in the form of “key: value” pairs.

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

What are object properties?

A

Properties are the values associated with a JavaScript object.

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

Describe object literal notation.

A

Opening and closing curly brace.

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

Use the delete operator.

“objectName”.”propertyName”

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 & Bracket Notation.

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

What are arrays used for?

A

When working on any kind of a list or with a set of values that are related to each other.

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

Describe array literal notation.

A

The square brackets.

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

They hold a related set of key/value pairs like “plain” objects, but the key for each value is its index number.
Arrays don’t have individual named indexes.

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 thelengthproperty of an array?

A

It is a number that represents how many items are in that 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

“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

Packing up code for reuse throughout a program, making code “dynamic”: meaning that it can be written once to handle many (or eveninfinite!) situations.

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

Describe the parts of a functiondefinition.

A
  1. The name of the function.
  2. A list of parameters to the function, enclosed in parentheses and separated by commas.
  3. The JavaScript statements that define the function, enclosed in curly brackets.
  4. (usually) Return statement.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Describe the parts of a functioncall.

A

We are writing the name of the function and placing()parentheses next to it. This causes thecode blockwithin the function’sdefinitionto be executed.
It doesn’t always require 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 functioncalland a functiondefinition?

A

A function definition is longer because it actually contains the Javascript statement that defines the function. Calling the function just requires writing the name with or without an argument.

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

What is the difference between aparameterand anargument?

A

Parameter is what’s in the parentheses when the function is being defined, an argument is when it’s being called.

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

Why are functionparametersuseful?

A

With no parameters, the end result is always the same.

They pass values into functions.

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

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

A

A return statementends the execution of a function, and returns control to the calling function.

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

Why do we log things to the console?

A

It is a method for developers to write code to inconspicuously inform the developers what the code is doing. Only useful for developers!
Also, DEBUGGING.

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

What is a method?

A

Amethodis afunctionwhich is apropertyof anobject.

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

How is a method different from any other function?

A

Function is a set of logic that can be used to manipulate data. While, method is function that is usedto manipulate the data of the object whereit belongs.

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

How do you remove the last element from an array?

A

The pop() method.

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

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

A

The floor() method.

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

How do you generate a random number?

A

The random() method.

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

How do you delete an element from an array?

A

The splice() method.

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

How do you append (add to end) an element to an array?

A

The push() method.

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

How do you break a string up into an array?

A

The split() method.

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

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

A

No, strings are immutable.

To make sure, double check with console.log.

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

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

A

45-50.

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

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

A

No.

For example, push() method already gives you a return value.

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

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

A

40 to 50.

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

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN.

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

Give 6 examples of comparison operators.

A

== (is loosely equal to), != (is not equal to), === (strict equal to), > (greater than), >= (greater than or equal to), < (less than), <= (less than or equal to).

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

What data type do comparison expressions evaluate to?

A

Boolean data type.

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

If statement evaluates & checks a condition. If the condition evaluates as 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
54
Q

Is”else”required in order to use anifstatement?

A

No.

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

Describe the syntax (structure) of anifstatement.

A

An “if” statement consists of the keyword ‘if’, followed by the condition written inside of the parentheses, an opening curly brace, a code to execute if the value is actually true, followed by the closing curly brace.

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), || (logical or), ! (logical not).

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

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

A

You use a comparison operator.

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

What is the purpose of a loop?

A

The purpose of loops isto repeat the same, or similar, code a number of times.

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

What is the purpose of aconditionexpression in a loop?

A

The condition is a boolean expression thatdetermines whether the ‘for’ should execute the next iteration.
“Should I stop?”

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

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

A

The repetition of going through the condition.

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

Whendoes theconditionexpression of awhileloop get evaluated?

A

An expression evaluatedbefore each pass through the loop (iteration). If this condition evaluates as true, statement is executed. When condition evaluates to false, execution continues with the statement after the while loop.

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

Whendoes theinitializationexpression of aforloop get evaluated?

A

When the loop begins.

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

Whendoes theconditionexpression of aforloop get evaluated?

A

It is evaluatedbefore each iteration.

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

Whendoes thefinalexpression of aforloop get evaluated?

A

At the end of every loop iteration, before the condition runs again.

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

Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?

A

Break.

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

What does the++increment operator do?

A

Adds one to the operand.
Returns a value.

If used postfix, with operator after operand (for example,x++), the increment operator increments and returns the value before incrementing.

If used prefix, with operator before operand (for example,++x), the increment operator increments and returns the value after incrementing.

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

How do you iterate through the keys of an object?

A

Using the “for in” statement.

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

Why do we log things to the console?

A

The console.log() is a function in JavaScript which isused to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.
It’s used for debugging purposes.

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

What is a “model”?

A

A model is a replica of something else.

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

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

A

Your HTML document.

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

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

A

The datatype object in javascript.

72
Q

What is a DOM Tree?

A

DOM is the makeup of an element & all of its contents.

73
Q

Give two examples ofdocumentmethods that retrieve a single element from the DOM.

A

querySelector(), getElementByID().

personal note: try to stick with just using querySelector().

74
Q

Give one example of adocumentmethod that retrieves multiple elements from the DOM at once.

A

querySelectorAll().

75
Q

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

A

You can access it again, especially when we’re working with a very complicated HTML document.

76
Q

Whatconsolemethod allows you to inspect the properties of a DOM element object?

A

console.dir() method.

77
Q

Why would ascripttag 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.

78
Q

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

A

It takes in as argument a CSS selector string.

It returns the first element within the document that matches the specified selector.

79
Q

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

A

It takes in as an argument a CSS selector string.
The document.querySelectorAll() returns a static node list representing a list of the document’s elects that matched the specified group of selectors.

80
Q

What is the purpose of events and event handling?

A

Interactivity with users.

81
Q

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

A

No.

There are optional parameters.

82
Q

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

A

addEventListener().

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

84
Q

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

A

An event object, which is about the event that just occurred while you are browsing.

85
Q

What is theevent.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

The read-onlytargetproperty of theeventinterface is which points to the element where the event occurred.
You can check on MDN if you are not sure.

86
Q

What is theclassNameproperty of element objects?

A

It sets or returns an element’s class attribute.

87
Q

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

A

You use a method to find the specific element of the DOM you want to work with (in our case the querySelector method), followed by a period, then the className property. On the right side of the = sign, you put the new CSS string class you want to change it to.

88
Q

What is thetextContentproperty of element objects?

A

The textContent property where it represents the text content of the node and its descendants.

89
Q

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

A

You use a method to find the specific element of the DOM you want to work with (in our case the querySelector method), followed by a period, then the textContent property. On the right side of the = sign, you put the new CSS string class you want to change it to.

90
Q

Is theeventparameter of an event listener callback always useful?

A

No. The “event” parameter is implicit. It’s already implied that the function is run w/ the event parameter being that the addEventListener() method only runs when the specified event is delivered to the target.

91
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
Why is storing information about a program in variables better than only storing it in the DOM?

A

More complicated. Setting variables makes it easy for future references when we’re dealing with many elements & makes it easier for Javascript.

92
Q

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

A

Focus event.

93
Q

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

A

Blur event.

94
Q

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

A

Input event.

95
Q

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

A

Submit event.

96
Q

What does theevent.preventDefault()method do?

A

To prevent the browser from doing the default behavior.

97
Q

What does submitting a form withoutevent.preventDefault()do?

A

The browser will reload and have the form’s values in the URL.

98
Q

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

A

Element property.

99
Q

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

A

value property.

100
Q

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

A

There are too many codes involved, so double check your work at every minor steps.

101
Q

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

A

You’ll notice your potential mistake sooner and fix it sooner.

102
Q

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

A

No - it only creates the element node. the appendChild method actually adds to the DOM.

103
Q

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

A

With the appendChild( ) method.

104
Q

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

A

A name: string that represents the attribute & a value.

105
Q

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

A
  1. Create the element - createElement ( )
  2. Give it content - createTextNode( ) (optional) or textContent property.
  3. Query the DOM that is going to hold the child aka the parent
  4. Add it to the DOM/append it to the parent element - appendChild( ).
106
Q

What is the textContent property of an element object for?

A

The textContent property in HTML is used to set or return the text content of the specified node and all its descendants.

107
Q

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

A

Element.setAttribute( );

className( );

108
Q

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

A

We have a piece of data that will always be reusable.

Allows us to test whether or not our code works.

109
Q

What is theevent.target?

A

The event.target points to the target of the event, which is the most specific element interacted with.

110
Q

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

A

Because of event bubbling.

111
Q

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

A

event.target.tagName

112
Q

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

A

Theclosest()method searchesupthe DOM tree for elements which matches a specified CSS selector.

113
Q

How can you remove an element from the DOM?

A

The element.remove(); method.

114
Q

If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

Structure the HTML so that you are able to add the event listener method to the PARENT element, and the new DOM elements will be added as child elements.

115
Q

What is the affect of setting an element todisplay: none?

A

Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist).

116
Q

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

A

The element.matches() method returns a boolean.
Thematches()method checks to see if the element aka event targetwould be selected by the providedselectorString, in other words, checks if the element “is” the selector. The selector string is the argument.

117
Q

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

A

getAttribute() method.

118
Q

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

A

Every step.

119
Q

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

A

We wouldn’t be using the querySelectorAll(); rather we would just be using the querySelector(); method. We would not be needing to use a for loop in our function for the listener parameter in our addEventListener() method.
We would have to re-do the event handling steps basically.

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

If we didn’t use a for loop, we wouldn’t be able to delegate the event from parent to child. That being said, we would have a querySelector() method to indicate where we are wanting that interactive response, individually set an event & function for the addEventListener() method, and create a function that only specifies to that one event target.

121
Q

What is JSON?

A

JSON stands forJavaScriptObjectNotation.
JSON is a format for storing and transporting data, and is often used when data is sent from a server to a web page.
Data turns into a string, then turns back into objects.

122
Q

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network. (Use the stringify() method to do this).
Deserialization is the reverse process: turning a stream of bytes into an object in memory. (Use the parce() method to do this).

123
Q

Why are serialization and deserialization useful?

A

Serialization allows us to convert the state of an object into a byte stream, which then can be saved into a file on the local disk or sent over the network to any other machine. And deserialization allows us to reverse the process, which means reconverting the serialized byte stream to an object again.

124
Q

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

A

The data has to be in the form of strings. This conversion of an object to a string can be easily done with the help of the JSON.stringify() method.

125
Q

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

A

The data received from a web server is always a string. In order to use that data you need to parse the data withthe JSON.parse()method which will returns a JavaScript object or array of objects.

126
Q

How to you store data inlocalStorage?

A

The setItem() method. Pass the key and value.

127
Q

How to you retrieve data fromlocalStorage?

A

The getItem() method. Pass the key.

128
Q

What data type canlocalStoragesave in the browser?

A

String data type.

129
Q

When does the’beforeunload’event fire on thewindowobject?

A

When window, document and the resources are about to be unloaded. Close or refresh the page.
People tend to use this event to confirm to the user if they actually want to leave this page to prevent data loss.

130
Q

What is amethod?

A

Amethodis afunctionwhich is apropertyof anobject.

131
Q

How can you tell the difference between a methoddefinitionand a methodcall?

A

A method definition actually describes what the method is doing. Calling it just gets the method to do what it is supposed to do.
Method definition has the “function” word as it is being defined. Calling does not.
Method has a code block, calling does not.

132
Q

Describe methoddefinitionsyntax (structure).

A

Property name, colon, function key word, parameter (optional), then code block.

133
Q

Describe methodcallsyntax (structure).

A

Property name, colon, function key word, parameter (optional), then code block.

134
Q

Describe methodcallsyntax (structure).

A

Object, period, followed by the type of method, then an argument.

135
Q

How is a method different from any other function?

A

A method, like a function, is a set of instructions that perform a task. The difference is thata method is associated with an object, while a function is not.

136
Q

What is thedefining characteristicof Object-Oriented Programming?

A

Objects can contain both data (as properties) & behavior (as methods).

137
Q

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

A

Encapsulation, abstraction, inheritance, and polymorphism.

138
Q

What is “abstraction”?

A

The most important part of the term “abstraction” boils down tobeing able to work with (possibly) complex things in simple ways.

139
Q

What does API stand for?

A

API is the acronym for Application Programming Interface.

140
Q

What is the purpose of an API?

A

API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. Each time you use an app like Facebook, send an instant message, or check the weather on your phone, you’re using an API.

In depth explanation: When you use an application on your mobile phone, the application connects to the Internet and sends data to a server. The server then retrieves that data, interprets it, performs the necessary actions and sends it back to your phone. The application then interprets that data and presents you with the information you wanted in a readable way. This is what an API is - all of this happens via API.

141
Q

What is”this”in JavaScript?

A

This is an implicit (implied) parameter of all Javascript functions.
Variable that holds the object you are currently working with.

142
Q

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

A

Implicit parameter means that it is available in a function’s code block even thought it was never included in the function’s parameter list or declared with var.

143
Q

Whenis the value ofthisdetermined in a function;call timeordefinition time?

A

It is determined when the function is called, not when it is defined.

144
Q

How can you tell what the value ofthiswill be for a particular function or methoddefinition?

A

You can’t. It’s determined at the call time.

145
Q

How can you tell what the value ofthisis for a particular function or methodcall?

A

The object that is to the left of the dot. If there is no value to the left of the dot when the function is called, thenby default,thiswill be the globalwindowobject.

146
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal inheritance.

147
Q

What is a prototype in JavaScript?

A

An object that contains properties and methods that can be used by other objects!
Definition of prototype not in javascript context: a first, typical or preliminary model of something, especially a machine, from which other forms are developed or copied.

148
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

Through the setPrototypeOf() method.

149
Q

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

A

In its prototypes!

150
Q

What does the new operator do?

A

It creates a new object, binds “this” to our new object, adds a property to “this” called prototype, which points to the constructor function.

151
Q

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

A

The property prototype.

152
Q

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

A

The prototype property.

153
Q

What does the “instanceof” operator do?

A
  1. Returns a boolean value.
  2. Checks to see if the prototype property of a constructor function appeals anywhere in the prototype chain of an object.
  3. Syntax: object, instanceof, then constructor function.
154
Q

What is a “callback” function?

A

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

155
Q

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

A

The setTimeout() function.

156
Q

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

A

The setInterval() function.

157
Q

What is the default time delay if you omit thedelayparameter fromsetTimeout()orsetInterval()?

A

Value of 0 is used, which means to execute immediately.

158
Q

What dosetTimeout()andsetInterval()return?

A

A numeric value which identifies the timer created by the call to pass to the cleartimeout() or clearinterval() method to cancel the timeout.

159
Q

What is a “callback” function?

A

A callback function is a function that is 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 thedocument, what is one way to delay the execution of a JavaScript function until some point in the future?

A

The setTimeout() function.

161
Q

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

A

The setInterval() function.

162
Q

What is the default time delay if you omit thedelayparameter fromsetTimeout()orsetInterval()?

A

Value of 0 is used, which means to execute immediately.

163
Q

What dosetTimeout()andsetInterval()return?

A

A numeric value which identifies the timer created by the call to pass to the cleartimeout() or clearinterval() method to cancel the timeout.

164
Q

What is a client?

A

Client-server denotes a relationship between cooperating programs in an application, composed of clients initiating requests for services and servers providing that function or service.

165
Q

What is a server?

A

The server component provides a function or service to one or many clients, which initiate requests for such services.

166
Q

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

A

Get method.

167
Q

What three things are on the start-line of an HTTPrequestmessage?

A

HTTP method, request target, HTTP version.

168
Q

What three things are on the start-line of an HTTPresponsemessage?

A

The protocol version, a status code, a status text.

169
Q

What are HTTP headers?

A

HTTP headerslet the client and the server pass additional information with an HTTP request or response.

170
Q

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

A

MDN.

171
Q

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

A

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

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

172
Q

What is AJAX?

A

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

173
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML.

174
Q

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

A

XMLHttpRequest.

175
Q

What event is fired byXMLHttpRequestobjects when they are finished loading the data from the server?

A

The load event.

176
Q

AnXMLHttpRequestobject has anaddEventListener()method just like DOM elements. How is it possible that they both share this functionality?

A

Prototypal inheritance.