LFZ JS Quiz Flashcards

1
Q

What is the purpose of variables?

A

To store information

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

How do you declare a variable?

A

with the var keyword

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 assignment operator =

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

$, _

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

Capitalization matters

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

What is the purpose of a string?

A

to store an array of characters

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

What is the purpose of a number?

A

to store a number or float

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

What is the purpose of a boolean?

A

to store true or false

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

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

assign the variable to another value with the assignment operator

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

What is the difference between null and undefined?

A

null is an empty object while undefined is nothing

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

For clarity in debugging

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

Give five examples of JavaScript primitives.

A

string, number, boolean, undefined, null

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

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

combining two stings together into one

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

to add numbers or concatenate strings

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

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

A

boolean

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

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

A

adds the result with itself

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

What are object properties?

A

the object’s variables

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

Describe object literal notation.

A

assign a var to an object by putting the object inside curly braces

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

using the delete keyword

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

using dot notation or 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

To store data, mainly lists

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

Describe array literal notation.

A

var foo = []

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

Stores data with index value as the keys

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

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

the amount of values it has

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

How do you calculate the last index of an array?

A

subtract 1 from the length method of the array object

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 group of code that can be reused and called with arguments

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

the name, the parameters, the code

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

the name, the 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 call just needs the function name and arguments. A function definition uses the function keyword and has code.

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

a parameter is like a temporary variable that takes in input, while the arguments are the input

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

Why are function parameters useful?

A

Pass data into the function

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

the return statement breaks out of the function and returns the value

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

For debugging

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

What is a method?

A

A function that is the 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

It is apart of an object and is called using dot notation or bracket notation

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

using the pop method of the array object

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

How do you generate a random number?

A

using the random method of the Math object

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

How do you delete an element from an array?

A

using the splice method of the array object

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

How do you append an element to an array?

A

using the push method of the array object

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

How do you break a string up into an array?

A

using the split method of the array object

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

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

A

No they do not, you can check the documentation

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

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

A

~50

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

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

A

No

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

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

A

~50

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

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
50
Q

Give 6 examples of comparison operators.

A

, <=, >=, ==, ===

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

Give 6 examples of comparison operators.

A

, <=, >=, !==, ===

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

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

Describe the syntax (structure) of an if statement.

A

if keyword, expression, and codeblock

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

What are the three logical operators?

A

&&, ||,

56
Q

What are the three logical operators?

A

&&, ||, !

57
Q

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

A

using logical operators

58
Q

What is the purpose of a loop?

A

To repeat something code a number of times

59
Q

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

A

To determine if the loop should start, run, and end

60
Q

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

A

the amount of loops are run

61
Q

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

A

at the start of the loop iteration

62
Q

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

A

before the loop is run

63
Q

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

A

before each loop iteration

64
Q

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

A

at the end of the loop iteration

65
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

66
Q

What does the ++ increment operator do?

A

it is short hand for adding 1 to itself

67
Q

How do you iterate through the keys of an object?

A

by using the for in loop

68
Q

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

A

focus

69
Q

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

A

blur

70
Q

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

A

input

71
Q

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

A

submit

72
Q

What does the event.preventDefault() method do?

A

prevents the events default action to be run

73
Q

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

A

resets the page

74
Q

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

A

elements

75
Q

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

A

value

76
Q

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

A

it’s easier to debug and you can see any errors

77
Q

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

A

using the addChild method

78
Q

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

A

no

79
Q

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

A

using the appendChild method or append method

80
Q

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

A

element attribute names and value

81
Q

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

A

create it, set the properties, and append it

82
Q

What is the textContent property of an element object for?

A

it holds the text content of the element

83
Q

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

A

Reusability and flexibility

84
Q

What is the event.target?

A

the target node of the point of interaction

85
Q

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

A

it removes it from the document flow and hides it

86
Q

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

A

it takes in a css selector and returns a boolean

87
Q

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

A

by using the getAttribute method

88
Q

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

A

at pretty much every point

89
Q

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

A

You would have to add another event listener to that new tab

90
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

You would have to have a lot of conditionals and over all use very messy code

91
Q

What is JSON?

A

A text-based data format that follows javacript’s object syntax

92
Q

What are serialization and deserialization?

A

Turning an object in memory into a stream of bytes to work with. Deserialization is the reverse; turning a stream of data into an object

93
Q

Why are serialization and deserialization useful?

A

to save data and use data

94
Q

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

A

by using the stringify method of the JSON object

95
Q

How to you store data in localStorage?

A

by using the setItem method of the localStorage object

96
Q

How to you retrieve data from localStorage?

A

by using the getItem method of the localStorage object

97
Q

What data type can localStorage save in the browser?

A

JSON

98
Q

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

A

Just before the page is unloaded/closed

99
Q

What is a method?

A

A function that is part of an object

100
Q

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

A

A method definition starts with the function keyword

A method call starts with the object name and has an argument list in parenthesis

101
Q

Describe method definition syntax (structure).

A

functionKey: function optionalName(optionalParameters) {code block}

102
Q

Describe method call syntax (structure).

A

objectName.Function()

103
Q

How is a method different from any other function?

A

It is apart of an object

104
Q

What is the defining characteristic of Object-Oriented Programming?

A

Abstraction

105
Q

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

A

Abstraction, Encapsulation, inheritance, and polymorphism

106
Q

What is “abstraction”?

A

simplifying complex ideas in to simple ones

107
Q

What does API stand for?

A

Application programming interface

108
Q

What is the purpose of an API?

A

To allow other people to interact with your program

109
Q

What is this in JavaScript?

A

An implicit parameter a part of all functions

110
Q

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

A

It is included in all functions even if it was never declared

111
Q

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

A

call time

112
Q

What does this refer to in the following code snippet?

A

the object literal, character

113
Q

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

A

‘it’s-a-me Mario!’ because this.firstname is referring to the object character whose firstName property is mario

114
Q

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

A

it’s-a-me, undefined! because you are just assigning the method definition to the var hello and not the object, so hello.firstName is undefined

115
Q

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

A

this will be undefined as it is not determined at definition

116
Q

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

A

by looking at what ever object’s property or method is when it is called

117
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal

118
Q

What is a prototype in JavaScript?

A

An object that delegates its methods and properties to other objects

119
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

Because the object’s prototype contains them

120
Q

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

A

At it’s prototype

121
Q

What does the new operator do?

A

Creates a blank object, adds __proto__ properties, binds the new instance to this, and returns this

122
Q

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

A

prototype

123
Q

What does the instanceof operator do?

A

returns a boolean if the instance on the left contains the prototype on the right

124
Q

What is a “callback” function?

A

A callback function is a function that is passed into another function as an argument

125
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

with the setTimeout function

126
Q

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

A

with the setInterval function

127
Q

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

A

0 (instant)

128
Q

What do setTimeout() and setInterval() return?

A

a timeoutID

129
Q

What is AJAX?

A

Ajax is a technique for loading data into part of a page

without having to refresh the entire page.

130
Q

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

A

XMLHttpRequest

131
Q

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

A

load

132
Q

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

A

They both inherit from the addeventlistener method

133
Q

What is Array.prototype.filter useful for?

A

It creates a new array based on filters you put

134
Q

What is Array.prototype.map useful for?

A

applying transforms to a whole array

135
Q

What is Array.prototype.reduce useful for?

A

To reduce an array to a single value