JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Represents and stores the values in our 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

By using var, let, or const before naming the variable

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

By using var to declare our variable, then an equal sign, and then our 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, underscore

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

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

A

A capital A is not the same as a lowercase a. Uppercase and lowercase letters are different values in JS.

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

Allows us to store and manipulate text

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

What is the purpose of a number?

A

Allows us to calculate sums, count, and perform other tasks (i.e determining size, moving position of an element, etc.)

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

Gives us a true or false value that tells our program which script to 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

This is the assignment operator. It assigns the value on the right to the variable on the left

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

Put the variable on a new line with a different value assigned to it

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 - an intentional absence of a value
Cannot be created by javascript only by humans
Undefined - accident; no one plans for this to have a value

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

The console does not log the variable name in the output so it is good practice to include it ourselves so that we see what the purpose of our value is (helps other people understand your data as well)

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

Give five examples of JavaScript primitives.

A

Undefined , null , boolean , string and number

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

The process of adding two strings together to create a new string

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 - math purposes

Concatenation - adding strings 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 true or false

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

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

An object is a collection of properties, and a property is an association between a name (or key) and a value.

A data type that allows you to store and manipulate data.

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

What are object properties?

A

Object properties are variables/key that gives us information about an object

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

Describe object literal notation.

A

Var declaration, then we have the object, within the curly opening and closing curly brace we have the keys: which are the property names and its value & the method

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

By using the delete operator and then object.property

Ex. delete hotel.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
Put the object name with a dot and then assign the new variable on the right
Ex. hotel.name = ‘new value’

Square brackets
Ex. hotel[‘name’] = ‘new value’

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

What are arrays used for?

A

They are used to store a list of values

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

Describe array literal notation.

A

Var declaration, variable name, and [ ]

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

Objects represent things in real life while arrays hold a list of values;

the key for each value in an array represents a number; all arrays come with a property which is length that is always being updated

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

zero

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

Length property counts how many items are in our 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

n-1

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

What is a function in JavaScript?

A

a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output.

A reusable block of code

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

Also called a function declaration:

  • Function keyword
  • Optional name
  • Comma-separated list of zero or more parameters
  • Opening curly brace to indicate start of our function
  • Optional return statement
  • Closing curly brace to indicate end of function code block
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
  • Function name

- A comma-separated list of zero or more 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 defines what needs to be done in order to achieve our goal; the call function helps executes those needs to achieve that goal

Function definition:
Has function keyword and code block

Function call:
Has arguments

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

Parameters:

  • Have a value that is not known
  • Placeholders for arguments

Arguments:

  • Have a value that is known
  • Replaces the parameter once it is called in
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Why are function parameters useful?

A
  • It holds our value until an argument gets called into it

- Helps us get reusable behaviors

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

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

A
  • Causes the function to produce a value we can use in our program.
  • 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

Why do we log things to the console?

A

To ensure that our code is working and correct (debugging purposes)

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

What is a method?

A

A method is a function that belongs to an object and executed with that object as a context.

or

A function that is a property of an object

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

How is a method different from any other function?

A

A method is associated with an object while a function is not

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

By using pop method

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

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

A

With Math.floor

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

Math.random( ) function

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

How do you delete an element from an array?

A

Splice ( )

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

How do you append an element to an array?

A

Append ( )

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

How do you break a string up into an array?

A

Split ( )

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

Strings are immutable; therefore they cannot be changed - only replaced. We can check by logging it through the console.

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-60; there’s a lot lol

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, because it is optional. Sometimes the value of a return is not useful while some are

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-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 equal to

!= - is not equal to

=== - strict equal to

>

  • greater than

< - less than

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

A boolean true or false

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

Evaluates our condition to see if it is true or false

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

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 (condition) {
statement1
} else {
statement2

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

What is the purpose of a loop?

A

It checks a condition repeatedly

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

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

A
  • Keeps our loop running as long as the condition is true

- Responsible for stopping

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

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

A
  • a process wherein a set of instructions or structures are repeated in a sequence a specified number of times or until a condition is met
  • Each time a loop runs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

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

A

-An expression is evaluated before each pass through the loop.

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

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

A

It’s executed once at the beginning of the loop

or

Evaluated once before the loop begins

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

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

A

Before each loop iteration

aka if the condition is true, it shall execute

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

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

A

At the end of each loop iteration and before the condition runs

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

What does the ++ increment operator do?

A

Adds, reassign, and substitutes one to our operand

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

Why do we log things to the console?

A

To label our values to make it easier for others and ourselves to understand
Good for debugging

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 an object, thing, person, etc.

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 browser page/HTML page

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 properties, methods, and events available for manipulating and creating web pages

Data object in JS

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

What is a DOM Tree?

A

Also known as a node tree; it is a structure that represents the parent node and the child node branches of the parent nodes

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

getElementById( )

querySelector( )

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

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

Assigning a variable to our element will allow us to work with it more than once
Stores location of the node

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 script tag need to be placed at the bottom of the HTML content instead of at the top?

A

The browser loads a script from top to bottom so putting our script tag at the bottom will allow all the html to load first before our JavaScript does

77
Q

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

A

Argument: a DOM string w/ CSS selector

Return: It returns the first element within the document that matches the specified selector or group of selectors; null is returned if no matches are found

78
Q

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

A

Argument: a DOM string w/ a CSS selector

Return: nodes list

79
Q

What is the purpose of events and event handling?

A

It allows our browser to feel more interactive

Events occur when users interact with a web page (click, hover, type, etc.)

Event handling occurs when: a function runs after being triggered when an event occurs

80
Q

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

A

No because you can call a function without a parameter

81
Q

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

A

addEventListener

82
Q

What is a callback function?

A

A function that is passed to another function as a parameter/argument is a callback function.

83
Q

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

A

Object that contains all info about the event that just occurred:
-The list that displays all the info that just occurred with the properties and its value

84
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 read-only target property of the Event interface is a reference to the object onto which the event was dispatched.
  • The target event property returns the element that triggered the event
  • MDN
85
Q

What is the difference between these two snippets of code?

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

A

The first code has the name of the function it is listening for:
-A function definition

The second code is set up where it is calling a function
-Will never have a return statement because we are not the one calling it; it tells handleClick to return undefined

86
Q

What is the className property of element objects?

A

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

87
Q

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

A

By using the className property Query, get a new value and assign the className property on that element

88
Q

What is the textContent property of element objects?

A

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

By using the textContent property

Query the element, get a new value on element, utilize textContent on the element and assign new value

90
Q

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

A

No; commonly useful but not always

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?

A

It would be more complicated

92
Q

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

A

It allows us to access the information much quicker when we have it stored vs when we do not have it stored

93
Q

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

A

Event = focus

94
Q

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

A

Event = blur

95
Q

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

A

Event = input

96
Q

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

A

Event = submit

97
Q

What does the event.preventDefault() method do?

A
  • Prevents the default event from happening/the default action that generally occurs will not occur
  • Should be required for every form event
98
Q

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

A

The default action will occur if there is no event.preventDefault

99
Q

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

A

HTMLFormElement.elements

Example: 
var inputs = document.getElementById("my-form").elements;
100
Q

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

A

The value property or .value

101
Q

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

A

Debugging will be hard when an error occurs

102
Q

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

A

We can see whether or not our console is logging the values properly

103
Q

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

A

No - it only creates the element node

104
Q

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

A

With the appendChild( ) method;

This method adds the element to the DOM tree

105
Q

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

A

A name - string that represents the attribute

A value

106
Q

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

A
  • Create the element - createElement ( )
  • Give it content - createTextNode( ) (optional)
  • Query the DOM that is going to hold the child aka the parent
  • Add it to the dom/append it to the parent element - appendChild( )
107
Q

What is the textContent property of an element object for?

A

Represents the text content of the node and its descendants.

108
Q

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

A
  • Element.setAttribute( );

- className( )

109
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

110
Q

What is the event.target?

A

The target property of the event object returns the element that triggered the event.

111
Q

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

A

It is possible due to event flow via event bubbling or event capturing

  • Event bubbling flows outwards to least specific one
  • Event capturing flows inwards to most specific one
112
Q

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

A

Event.type property

113
Q

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

A
  • Argument = selectors; a DOMstring containing a selector list
  • Return = closestElement; which is the closest ancestor of the selected element; may be null
114
Q

How can you remove an element from the DOM?

A

element.remove( )

115
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

With event delegation, you can add the event listener to one parent and it will analyze the bubbled events to find a match on child elements

116
Q

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

A

The element will disappear and be removed from the document flow

117
Q

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

A

Checks to see if the Element would be selected by the provided selectorString – in other words – checks if the element “is” the selector.

  • Argument: takes a string that is a css selector
  • Returns: a boolean
118
Q

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

A

Element.getAttribute( )

119
Q

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

A

Every chance you get aka all steps LOL

120
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

Our JavaScript code would have more code than it should have because we would have to write something for the parent and its children ??

121
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

We would have more functions that target each specific action vs having one code that targets these

122
Q

What is JSON?

A

-Stands for JavaScript Object Notation

JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null.

123
Q

What are serialization and deserialization?

A

Serialization: converting a native object to a string so it can be transmitted across the network

Deserialization: Converting a string to a native object

124
Q

Why are serialization and deserialization useful?

A
  • Allows you to transmit data across a network and save them to a hard drive
  • Allows you to convert string to object and vice versa
125
Q

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

object -> string

A

JSON.stringify()

126
Q

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

A

JSON.parse()

127
Q

How do you store data in localStorage?

A

storage.setItem(keyName, keyValue);

128
Q

How do you retrieve data from localStorage?

A

storage.getItem(keyName);

129
Q

What data type can localStorage save in the browser?

A

String data only

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

131
Q

What is a method?

A

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

In JavaScript functions themselves are objects, so, in that context, a method is actually an object reference to a function.

132
Q

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

A

A method definition has:
A function keyword, a code block, and a function being assigned to an object

A method call has:
Name of method, object, and argument

133
Q

Describe method definition syntax (structure).

A

Property name, colon, function key word, parameter list, and a code block

134
Q

Describe method call syntax (structure).

A

Method name and method property
Separated with a dot
ex. character.description( );

135
Q

How is a method different from any other function?

A

A function is independent, whereas a method is a function linked with an object.

  • Function — a set of instructions that perform a task.
  • Method — a set of instructions that are associated with an object.
136
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

137
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

138
Q

What is “abstraction”?

A

Being able to work with (possibly) complex things in simple ways
Ex. light switch example

139
Q

What does API stand for?

A

Application Programming Interface

140
Q

What is the purpose of an API?

A

A set of functions that allows applications to access data and interact with external software components, operating systems, or micro-services.

To simplify, an API delivers a user response to a system and sends the system’s response back to a user.

141
Q

What is this in JavaScript?

A

An implicit parameter

Purpose: gets the value of the object that the behavior of the function its attached to

142
Q

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

A

This 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 with var

143
Q

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

A

It is determined when the function is called (call time)

144
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

This refers to nothing cause there is no object attached to it

145
Q

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

character.greet();

A

It’s-a-me, Mario!

There is an object attached to the property greet

In this case, the greet method is being called on the character object

146
Q

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

var hello = character.greet;
hello();
A

It’s-a-me, undefined!

  • There is no object attached so the computer cannot register what the value is when asking for the name
  • Hello has no properties
147
Q

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

A

When a method is being written, and this is being used, there is no value until it is called

148
Q

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

A

If an object is attached to it on the left

149
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype inheritance - JavaScript objects give certain behaviors (methods) or data (properties) to other objects.

150
Q

What is a prototype in JavaScript?

A

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

151
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

The methods are defined on a prototype object that gets borrowed when needed

152
Q

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

A

The prototype

153
Q

What does the new operator do?

A

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.

Constructor function - The constructor method is a special method of a class for creating and initializing an object instance of that class.

Does four things:
-Creates a blank, plain JavaScript object.

  • Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
  • Binds the newly created object instance as the ‘this’ context (i.e. all references to this in the constructor function now refer to the object created in the first step).
  • Returns this if the function doesn’t return an object.
154
Q

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

A

Prototype property - defines a property that is shared by all objects created with that function, rather than by just one instance of the object type.

155
Q

What does the instanceof operator do?

A

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

156
Q

What is a “callback” function?

A

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

157
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( ) function - sets a timer which executes a function or specified piece of code once the timer expires.

Note: Is a global function, so you can call it directly by name without any object to the left of the dot. e.g. setTimeout(func, delay).

158
Q

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

A

setInterval( ) function - repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.

159
Q

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

A

For setTimeout - 0; it is executed immediately

For setInterval - 0; it is executed immediately

160
Q

What do setTimeout() and setInterval() return?

A

setTimeout ( ) returns: a positive integer value which identifies the timer created by the call

setInterval ( ) returns: a numeric, non-zero value which identifies the timer created by the call

161
Q

What is a client?

A
  • Service requesters

- A piece of software using another piece of software

162
Q

What is a server?

A

The providers of a resource or service

163
Q

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

A

“GET” method

164
Q

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

A

-An HTTP method - verb or noun that describes action to be performed
Verb: GET, PUT, POST
Noun: HEAD or OPTIONS

  • The request target - usually a URL
  • The HTTP version - defines structure of the remaining message
165
Q

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

A
  • Protocol version; usually HTTP/1.1
  • A status code, indicating success or failure
  • A status text; text description of status code that helps human understand HTTP message
166
Q

What are HTTP headers?

A
  • Let the client and the server pass additional information with an HTTP request or response.
  • An HTTP header consists of its case-insensitive name followed by a colon ( : ), then by its value.
167
Q

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

A

HTTP Headers at MDN

168
Q

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

A

No

169
Q

What is AJAX?

A

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

Data is often sent in JSON

170
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

171
Q

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

A

XMLHttpRequest

172
Q

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

A

LOAD

173
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

Prototype inheritance

174
Q

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

A

A set of statements/instructions within a curly brace

Examples:
Function code block
CSS code block
Loop code block

175
Q

What does block scope mean?

A

Block Level Scope: This scope restricts the variable that is declared inside a specific block, from access by the outside of the block.

Block scope - variables live and die within the curly braces/within its block

176
Q

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

A

Both are block-scoped variables

177
Q

What is the difference between let and const?

A

Let:

  • Mutable: values can be reassigned
  • Can be declared without initialization

Const:

  • Immutable - cannot be reassigned or redeclared
  • Needs to be initialized with a value after const declaration
  • The const keyword creates a read-only reference to a value. The read-only reference cannot be reassigned but the value can be changed.
178
Q

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

A

We are only adding to the array, not modifying it

179
Q

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

A

If we have a value that we intend to reassign, then we would use the let. If we need a variable to be immutable or not reassign, we would use const

180
Q

What is the syntax for writing a template literal?

A

let simple = This is a template literal;

Variable declaration, variable name, a string wrapped in between two backticks

${variable name}
-Dollar sign, curly brace, variable name

181
Q

What is “string interpolation”?

A

String interpolation is replacing placeholders with values in a string literal

182
Q

What is destructuring, conceptually?

A

Getting the data out of the array or object/extracting

183
Q

What is the syntax for Object destructuring?

A

let { property1, property2} = object;

Variable declaration, opening curly brace, property key names, closing curly brace, equal sign and object name destructuring from

184
Q

What is the syntax for Array destructuring?

A

Variable declaration, square brackets [ ] and items in between the brackets, equal assignment operator, and array name

Ex. let [x, y, z] = getScores();

185
Q

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

A

The syntax is the opposite for destructuring and creating.
Destructuring (curly or square bracket) is on the left, creating is on the right

When creating object/array literals, we declare the variable declaration first, the object/array variable name, followed by an equal sign and the opening curly braces or brackets

When destructuring, we have the variable declaration, the curly brace or bracket, an equal sign, and then the variable name of the object or array

186
Q

What is the syntax for defining an arrow function?

A
Either var, let, or const
Variable name
Assignment operator
Parentheses
Parameters (optional)
The arrow => 
The expression

**If it is a block syntax, place the expression within a curly brace with the return keyword

187
Q

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

A

If there is no curly brace, this indicates that the expression is not a part of the function

Curly brace represents that its a statement

188
Q

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

A

‘this’ is determined by call time in arrow function