Javascript Flashcards

1
Q

What does = operator do in Javascript?

A

It is the assignment operator typically used for variables

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

Which keyword is used to declare a variable in Javascript?

A

var

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

Which characters is a Javascript variable allowed to begin with?

A
  • Uppercase letters
  • lowercase letters
  • underscore
  • dollar sign
  • numbers (cannot use numbers in the beginning of the variable however)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are quotation marks used for in Javascript?

A

Used for string variables

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

What is the purpose of strings in Javascript?

A

Storing and manipulating text

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

What is the purpose of booleans in Javascript?

A

To find out if an expression is true or false

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

What is the purpose of numbers in Javascript?

A

Sets up a basis of counting and quantifies any math related value

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

What does null mean in JavaScript?

A

Intentional absence in value

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

What data types can object properties hold?

A

They can basically hold any variable like strings, numbers, booleans, etc

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

Describe the syntax (structure) of object literals in JavaScript?

A
var variableName = {
       key: 'value1'
       key2: 'value2'
];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the principal use of arrays?

A

Organized lists for variables that can be called upon

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

Describe the syntax (structure) of array-literals in JavaScript

A

var variableName = [value1, value2, value3];

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

How can you access the last element of an array?

A

(Length property of an array) subtract by 1

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

What are the five parts of a function definition?

A
function name(parameters) {
   code
}
- The function keyword, the name for a function (optional), the parameters, the code block, and the return statement(optional)
- Function names can have letters, digits, underscores, and dollar signs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you call a function?

A
  • Using the function name with the parentheses and semicolon

Example: myFunction();

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

What is the difference between a parameter and an argument?

A

Parameter - listed inside the parentheses in a function. Behave as local variables
Argument - values received by the function when it is invoked

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

What does strictly equal mean?

A

=== It means that the values being compared are of the same value and data type

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

What is the logical <b>and</b> operator?

A

Both statements have to be true in order to result in true.

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

Can you name some comparison operators?

A
== equal to
=== equal value and equal type
!= not equal
!== not equal or not equal type
> greater than
< less than
>= greater than or equal to
<= les than or equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

When is the first expression in the parentheses for a for loop (known as the initialization) evaluated?

A

The first expression (initialization) is used once before the code block is executed.
Typically written as (let i = 0).
Sets up the loop

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

When is the second expression in the parentheses for a for loop (known as the condition) evaluated?

A

The second expression (condition) is used to define the condition for executing the code block.
This is typically written as (i < number). The number representing how many times the loop will occur.
Lets computer know when to stop looping.

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

When is the third expression in the parentheses for a for loop (known as the final expression) evaluated?

A

The third expression (the final expression) is used to change the value each time the code block in the loop has been executed.
Can be written as (i++)
Helps to get the loop closer to stopping.

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

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

A

Dictates when the loop will stop running.

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

What is the purpose of the final expression in a for loop?

A

Gets the loop closer to stopping

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

What is DOM?

A

Document Object Model which is created when a web page is loaded.
Defines a standard for accessing documents

HTML DOM is a standard object tree model and programming interface for HTML.
Sets the standard for how to get, change, add, or delete HTML elements

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

What does document.querySelector() return?

A

Returns the first element within a document that matches a specified selector or group of selectors. If no matches then it returns null.

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

How do you modify the text of elements on the DOM?

A
var simplifiedElement = document.querySelector('id.idName');
simplifiedElement.textContent = 'insert text here';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What arguments does the addEventListener method make?

A

document.addEventListener(event, function, useCapture)
Event - required, the event name, do not use “on” as prefix
Function - required, the function to run when event occurs. When the event occurs the object is passed to the function as the first parameter.
useCapture - optional, a boolean. Specifies if the event should be executed in the capturing or bubbling phase

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

Give five examples of Javascript events that can be listened for

A

Mouse - events that relate to the computer mouse. Used to notify when mouse is clicked, doubleclicked, up/down events, right-click, movement in and out of an element, text selection, etc.

DOMContentLoaded - occurs on events related to events being loaded on the document

Animation - events related to Web Animation API. Used to respond to changes in animation (ex. when it starts/ends)

Composition - Events related to entering text “indirectly” (i.e. text entered via a speech to text engine or using special key combinations that modify keyboard presses to represent new characters in another language

Drag’n’drop, Wheel - Events derived from mouse events. While this is occurred when using the mouse wheel or drag/drop

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

What does document.createElement() take as its assignment?

A

It takes tagName or an HTMLUknownElement if tagName isn’t recognized.

For example (h1, div, etc)

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

What does document.createElement() return?

A

Returns the new element

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

How do you append elements to the DOM?

A

appendChild(aChild)

Example ($parent.appendChild($child)).

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

What is the purpose of variables?

A

To store values that can be used later

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

How do you initialize (assign a value to) a variable?

A

var varName = value

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

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

A

Variables with different casing can have completely different values

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

What does = operator mean in JavaScript?

A

It means assignment as in it assigns a variable to a value

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

How do you update the value of a variable?

A

varName = new value

No need to declare value again using var because it has already been stored

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

What is the difference between null and undefined?

A

Null = it was intentionally left blank

Undefined = can be missing a value for any multiple of reasons

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

Why is it a good habit to include “labels’ when you log values to the browser console?

A

Provides clarity to other users and yourself in the future.

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

Give five examples of JavaScript data type primitives.

A
  • number
  • string
  • boolean
  • undefined
  • null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What data type is returned by an arithmetic operation?

A

Number data type

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

What is string concatenation?

A

Combining string values together

Strings are immutable, cannot be changed

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

What purpose(s) does the + plus operator serve in JavaScript?

A

Adds or concatenates values together

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

What data type is returned by comparing two values (, ===, etc.)?

A

Boolean data type

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

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

A

Adds or concatenates a value on the right side to the left side

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

What are objects used for?

A

To group together a set of variables and functions

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

What are object properties?

A

Variables that are part of an object.

Individual keys that correlate to a value

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

Describe object literal notation?

A

Object literal notation contains curly braces ({ })

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

How do you remove a property from an object?

A

Using the delete operator and the object.property

Ex. delete object.property

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

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

A

Using a . to call on the object property
Using [ ] to call on the object property

square bracket notation - contains a variable with values you actually want
dot notation - straight away that calls on an object’s property

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

What are arrays used for?

A

Stores a set of values/lists of data

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

Describe array literal notation.

A

[ ]

var arrayName = [value1, value2, value3];

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

How are arrays different from “plain” objects?

A
  • They don’t need an individual key or value
  • Arrays don’t have alpha-numeric indexes (only numeric)
  • Arrays have a length property
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
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
56
Q

What is the length property of an array?

A

Stores the value of the length of the array’s list via arrayName.length

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

How do you calculate the last index of an array?

A

arrayName - 1

Length is true count of value, the - 1 takes into account of indexing

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

What is the notation for calling an array in an object?

A

objectName.objectProperty.objectValue[#];

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

What is a function in JavaScript?

A

Sets up code that can be called upon any time in a program.

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

Describe the parts of a function definition.

A
  • function keyword
  • function name (optional)
  • function parameters (optional)
  • Code block {using curly braces}
  • Return statement (optional)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

Describe the parts of a function call.

A
  • functionName
  • (arguments, in, parentheses)
  • Does not require arguments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

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

A

Function Definition - function is defined with parameters in the parentheses

Function Call - function is called with arguments in the parentheses

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

What is the difference between a parameter and an argument?

A

Parameters are used when defining a function, placeholder for values

Arguments are used when calling a function, values are known

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

Why are function parameters useful?

A

Function parameters are useful because it allows other people to pass arguments when the function is called

Allows for reusability instead of single use (no parameters means one result)

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

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

A

The return statement produces a value and exits the function (no code after this return within the code block will run

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

Why do we log things to the console?

A

To make sure that we get the proper output from our code

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

What is a method?

A

A function which is a property of an object

i.e. Math.max(numberValues );

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

How is a method different from any other function?

A

Functions are objects while methods reference an object to a function

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

How do you remove the last element from an array?

A

arrayName.pop();

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

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

A

Math.floor();

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

How do you generate a random number?

A

Math.random();

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

How do you delete an element from an array?

A

object.splice();

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

How do you append an element to an array?

A

object.push();

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

How do you break a string into an array?

A

object.split();

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

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

A

No, strings are immutable.

Use the console.log and check the original string to see if it changed

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

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

A

There are a lot… like 40-50

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

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

A

Not always necessary

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

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

A

There are a lot.. like 40-50

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

How to learn via documentation?

A
  1. Read the blurb that provides a definition/summary of the term/method you’re looking at.
  2. Syntax
    • Read parameters
    • Ignore info that doesn’t pertain to what you’re looking for
  3. Return Value
  4. Read original sample code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

Give 6 examples of comparison operators

A
>,
<
>=
<=
==
===
!=
!==
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
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
83
Q

What is the purpose of an if statement?

A

Create a path of code dependent on the user’s input/data

This is done by checking a condition. If the condition is true then the code block is executed.

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

Is else required in order to use an if statement?

A

No you can use just the if statement

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

Describe the syntax (structure) of an if statement?

A

keyword if
condition (yourConditionHere)
Code Block { }
Code to execute if true (inside the code block)

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

What are the three logical operators?

A

&&
||
!

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

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

A

Using a logical operator

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

What is the purpose of a loop?

A

To run a piece of code a repeated number of times so long as the condition in the loop is true.

Once the condition of the loop is false then the code stops.

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

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

A

Sets the code up to repeatedly run so long as the conditions remain true and will stop the loop when the condition is false

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

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

A

Each time the loop repeats

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

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

A

Before each iteration

92
Q

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

A

In the beginning, before the loop happens

The initialization expression sets up the loop by creating a counter

Initialization is written as: var i = 0;

93
Q

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

A

After initialization and before each loop iteration

94
Q

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

A

At the end of each loop iteration (before the next evaluation of the condition)

95
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

96
Q

What does the ++ increment operator do?

A

Increments its operand and returns a value that reassigns the initialization value

97
Q

How do you iterate through the keys of an object?

A

Use a for in loop

98
Q

Why do we log things to the console?

A

In order to check to see if our code is functional and what is occurring

99
Q

What is a “model”?

A

A recreation of an existing concept. In this case a recreation of the web page.

100
Q

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

A

The HTML document

101
Q

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

A

The datatype object

102
Q

What is a DOM Tree?

A

A parent element with its child elements with its nodes.

103
Q

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

A

querySelector( )

getElementById( )

104
Q

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

A

querySelectorAll( )

105
Q

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

A

So it just runs once, stores the value in the variable, and you can just pull the up the result from the variable

106
Q

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

A

console.dir( )

107
Q

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

A

HTML elements are read from top to bottom.

The script is put at the end so things can populate before the script line is executed

108
Q

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

A

Argument of a string that contains a css selector and the return will be the first element that matches that selector

109
Q

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

A

The argument is a string with the value of a CSS selector

It returns a node list which is a like an array object BUT ITS NOT AN ARRAY

110
Q

What is DOM?

A

The Document Object Model

A Javascript object that is the model of the HTML document.
- It is not the HTML itself

111
Q

What is the purpose of events and event handling?

A

When user interaction occurs this allows things like events and event handling to respond to certain instances

112
Q

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

A

No it depends on the method or function but usually only the event and function name is required.

113
Q

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

A

addEventListener( );

114
Q

What is a callback function?

A

A function that is called in another function as an argument. This is used to complete some kind of action.

115
Q

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

A

The object that has all the data for the event that just happened

116
Q

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

A

Reads the object that was used in order for the event to occur. You could check this via console.log and you could get more info from MDN.

117
Q

What is the difference between these two snippets of code?

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

A

The first one there is a function being named

The second one there’s a function with a return value

118
Q

What is the syntax of an event listener?

A

element.addEventListener (‘event’, functionName, [Boolean] );

119
Q

What is the className property of element objects?

A

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

120
Q

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

A

var $varName = document.querySelector(‘itemName’)

$varName.className = (‘updatedClassName’);

121
Q

What is the textContent property of element objects?

A

Represents the text content of the node and its descendants.

122
Q

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

A

var $varName = document.querySelector(‘.className’)

$varName.textContent = ‘Text Content’;

123
Q

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

A

Not always.

The event parameter helps in understanding that it is an event handler function

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

You would have to add more text content and turn certain text content into numbers.

125
Q

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

A

It’s easier for JavaScript to work with it

Allows for efficiency and easy to edit if issues arise

126
Q

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

A

‘focus’ event will occur

127
Q

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

A

‘blur’ event will occur

128
Q

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

A

‘input’ event will occur

129
Q

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

A

‘submit’ event will occur

130
Q

What does the event.preventDefault() method do?

A

Prevents the default behavior of an event from occurring

131
Q

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

A

Submits the form and creates a new form

132
Q

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

A

The value property

133
Q

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

A

Knowing where progress is and when code broke/contained error

134
Q

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

A

Knowing when an error occurred and seeing when things are happening in real time

135
Q

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

A

Elements property on the form which contains individual properties

136
Q

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

A

No it stores the element node in a variable

137
Q

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

A

appendChild method

Which adds a child element to the parent element. It will be added as the last child.

138
Q

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

A

name = a DOMstring specifying the name of the attribute whose value is to be set

value = a DOMstring containing the value to assign to the attribute

139
Q

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

A

Create the element
Set the attributes to the element
Query the DOM for the target parent element
Append the child to the parent element

node.appendChild(aChild);

140
Q

What is the textContent property of an element object for?

A

Used to read what the text content is but can also assign new text content as well

141
Q

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

A

element. setAttribute( )

element. className( )

142
Q

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

A

Get to test out the code to make sure its functional

Get to reuse the function

143
Q

What is the event.target?

A

Refers to an object that the event is being done on

144
Q

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

A

Because the descendent elements are children of the one element that is being listened on due to the flow events from event bubbling (child to parent flow)

145
Q

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

A

event.target.tagName

146
Q

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

A

Takes a name of a selector in DOMString that can be a selector like elementName, className, etc.

147
Q

How can you remove an element from the DOM?

A

elementName.remove( )

148
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

Put the event listener on the parent element that will contain these new elements

149
Q

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

A

The content and any of it’s children’s content wouldn’t be shown

150
Q

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

A

It takes the selectorString which is a string representing the selector that will be tested

151
Q

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

A

getAttribute( );

152
Q

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

A

After any piece of code that can alter the webpage

153
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

createElement( )

154
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

display: none

155
Q

What is JSON?

A

JavaScript Object Notation is a standard text-based format for representing structured data based on JavaScript object syntax.

156
Q

What are serialization and deserialization?

A

Serialization = turning an object that’s stored into a bytes to store it in a desk or send over the network

Deserialization = turning bytes into an object in storage

157
Q

Why are serialization and deserialization useful?

A

Serialization/Deserialization is important because it stores and transfers objects through a standardized process

158
Q

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

A

JSON.stringify( )

159
Q

How do you deserialize a JSON string using JavaScript?

A

JSON.parse( )

160
Q

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

A

var dataStructure = JSON.parse(jsonString);

161
Q

How do you store data in localStorage?

A

localStorage.(‘key’, ‘value’);

162
Q

How do you retrieve data from localStorage?

A

localStorage.getItem(‘value’);

163
Q

What data type can localStorage save in the browser?

A

Strings

164
Q

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

A

Allows a web page to trigger a confirmation dialog asking the user if they really want to leave the page

165
Q

What is a method?

A

A function that is a property of an object

Example:
objectName.methodName(argumentName)

166
Q

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

A

Method = Has a code block that defines the method, has the function keyword, has parameters, function will be assigned to a property

Method call = is a property of the object and contains arguments

167
Q

Describe method definition syntax (structure).

A
Declare the Object methods will work with:
var objectName = {
   methodName: function ( ) {
      return valueName;
   }
};
168
Q

Describe method call syntax (structure)

A

objectName.methodName(arguments)

169
Q

How is a method different from any other function?

A

Functions are objects while methods reference an object from the function

170
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

171
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

172
Q

What is “abstraction”?

A

Being able to work with complex things in simple ways.

173
Q

What does API stand for?

A

Application Programming Interface

174
Q

What is the purpose of an API?

A

Give programmers a way to interact with a system in a simple, consistent fashion

175
Q

What is this in Javascript?

A
  • An implicit parameter of all Javascript functions
  • Its value is determined when it is called
  • Value of this is determined as the object left of the dot when the function is called (as a method)
  • If no value to left of the dot when function is called then it is by default the global window object
  • If you cannot see the function being called, then you do not know what the value of this will be
176
Q

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

A

A parameter that is available in a function code block even though it was never in the function parameter list or declared with var

177
Q

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

A

Call time

178
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

There is no this value

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

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

character.greet();

A

It’s-a-me, Mario!

Because there is an object being assigned to character and since character object is to the left of the greet method which contains ‘this’ then it will use character as the object for this.firstName

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

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

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

Undefined

hello is a free floating variable. Since its being called without a stated object then the default object is window. Because window has no firstName property then there’s nothing to return

181
Q

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

A

You don’t. Because there’s no object so there’s no method being called

182
Q

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

A

Value of this is whatever object is to the left of the method call.

183
Q

What kind of inheritance does JavaScript programming language use?

A

Prototype-based inheritance which is used to move properties and methods to the prototype object so other objects can use prototype object to perform tasks

184
Q

What is a prototype in JavaScript?

A

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

185
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

Set these methods in a prototype variable and then put the object as a parameter when calling the method

186
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 respective prototype object

187
Q

What is the syntax to set a prototype to an object?

A

Object.setPrototypeOf(objectName, prototype)

objectName = object that will have its prototype set

prototype = the object’s new prototype (object or null)

The return will be the specified object

188
Q

How would you write a prototype method?

A
var prototypeName = {
   propertyName: function ( ) {
   }
};

Object.setPrototypeOf(objectName, prototypeName);

189
Q

What does the new operator do?

A

Allows user to create a user-defined object type or a built-in object type that has a constructor function

  • Creates a blank JavaScript object
  • Adds a property to the new object’s prototype that links to the constructor function’s prototype object
  • When this is used it will reference to the new operator’s object
  • Returns this if object is non-existent
190
Q

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

A

prototype property

191
Q

What does the instanceof operator do?

A

Checks if there’s a prototype property in an object

192
Q

What is the syntax of the new operator?

A

new constructor[ ( [arguments] ) ]

constructor = class or function that specifies the type of object

arguments = a list of values the constructor will be called with

193
Q

What is the syntax of using an instanceof operator?

A

object instanceof constructor

object = the object to test
constructor = function to test again
194
Q

What does an instanceof operator return?

A

A boolean value

195
Q

What does the new operator return?

A

An object or this if an object isn’t returned

196
Q

What is the syntax for a constructor function in regards to creating an object?

A
function objectName(parameter 1, 2, 3) {
   this.parameter1 = parameter1;
   this.parameter2 = parameter2;
   this.parameter3= parameter3;
}
197
Q

What is a “callback” function?

A

A function that is used in another function as an argument

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

199
Q

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

A

setInterval( )

200
Q

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

A

Value of 0 meaning execute the code immediately or the next event cycle

201
Q

What do setTimeout( ) and setInterval( ) return?

A

timeoutID which is a positive integer

202
Q

What is the syntax of setTimeout( )?

A

setTimeout (function[delay, arg1, arg2, …] )

function = function to be used when timer expires

delay = time in milliseconds that the function is to be executed

arg1, arg2… = additional arguments for the function being executed

203
Q

What is the syntax of setInterval( )?

A

var intervalID = setInterval (function, delay , arguments)

function = function to be executed

delay = time in milliseconds interval occurs

arguments = list of arguments to pass through the function

204
Q

What is the syntax of clearInterval( )?

A

clearInterval ( intervalID )

intervalID = identifier of the setInterval that is supposed to be cleared

205
Q

What is a client?

A

A software uses a service or resource from a server

206
Q

What is a server?

A

A software provides a service or resource to a client

207
Q

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

A

GET

208
Q

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

A
  • An HTTP method
  • The request target
  • The HTTP version
209
Q

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

A
  • The protocol version
  • The status code
  • Status text
210
Q

What are HTTP headers?

A

They let the client and server pass additional info with an HTTP request or response

Gives additional info (similar to head element in html)

211
Q

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

A

MDN

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

212
Q

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

A

No because some HTTP methods don’t need one

213
Q

What is AJAX?

A

Web application allows the request of data without having to reload the whole page

214
Q

What does AJAX acronym stand for?

A

Asynchronous JavaScript And XML

215
Q

Which object is built in browser for making HTTP requests in Javascript?

A

XMLHttpRequest

216
Q

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

A

‘load’

217
Q

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

A

Prototype inheritance

218
Q

What is the JavaScript Event Loop?

A

One of the four major concepts in JavaScript.

The event loop takes the first item from callback queue and sends it to the JavaScript callback stack. Once the process is finished the event loop pushes the next callback item to the callback stack.

219
Q

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

A

Blocking: code takes effect immediately when the block is being processed

Non-blocking: code takes effect at the end of the block being processed.

220
Q

What are the four major concepts of JavaScript?

A

Prototypal Inheritance
How this works
Closures
Event Loop

221
Q

What must the return value of myFunction be if the following expression is possible?

myFunction( ) ( );

A

A function

The return of myFunction is being called

222
Q

What does this code do?

const wrap = value => {
   ( ) => {
      value;
   }
}
A

Value of wrap is a function definition

223
Q

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

A

When it is defined

224
Q

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

A

Closures

225
Q

What is a closure?

A

A closure is a combination of a function and the lexical environment within which the function was declared