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
Describe array literal notation.
var foo = []
26
How are arrays different from "plain" objects?
Stores data with index value as the keys
27
What number represents the first index of an array?
0
28
What is the length property of an array?
the amount of values it has
29
How do you calculate the last index of an array?
subtract 1 from the length method of the array object
30
What is a function in JavaScript?
A group of code that can be reused and called with arguments
31
Describe the parts of a function definition.
the name, the parameters, the code
32
Describe the parts of a function call.
the name, the arguments
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function call just needs the function name and arguments. A function definition uses the function keyword and has code.
34
What is the difference between a parameter and an argument?
a parameter is like a temporary variable that takes in input, while the arguments are the input
35
Why are function parameters useful?
Pass data into the function
36
What two effects does a return statement have on the behavior of a function?
the return statement breaks out of the function and returns the value
37
Why do we log things to the console?
For debugging
38
What is a method?
A function that is the property of an object
39
How is a method different from any other function?
It is apart of an object and is called using dot notation or bracket notation
40
How do you remove the last element from an array?
using the pop method of the array object
41
How do you generate a random number?
using the random method of the Math object
42
How do you delete an element from an array?
using the splice method of the array object
43
How do you append an element to an array?
using the push method of the array object
44
How do you break a string up into an array?
using the split method of the array object
45
Do string methods change the original string? How would you check if you weren't sure?
No they do not, you can check the documentation
46
Roughly how many string methods are there according to the MDN Web docs?
~50
47
Is the return value of a function or method useful in every situation?
No
48
Roughly how many array methods are there according to the MDN Web docs?
~50
49
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
50
Give 6 examples of comparison operators.
, <=, >=, ==, ===
51
Give 6 examples of comparison operators.
, <=, >=, !==, ===
52
What data type do comparison expressions evaluate to?
Boolean
53
Is else required in order to use an if statement?
no
54
Describe the syntax (structure) of an if statement.
if keyword, expression, and codeblock
55
What are the three logical operators?
&&, ||,
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
using logical operators
58
What is the purpose of a loop?
To repeat something code a number of times
59
What is the purpose of a condition expression in a loop?
To determine if the loop should start, run, and end
60
What does "iteration" mean in the context of loops?
the amount of loops are run
61
When does the condition expression of a while loop get evaluated?
at the start of the loop iteration
62
When does the initialization expression of a for loop get evaluated?
before the loop is run
63
When does the condition expression of a for loop get evaluated?
before each loop iteration
64
When does the final expression of a for loop get evaluated?
at the end of the loop iteration
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
66
What does the ++ increment operator do?
it is short hand for adding 1 to itself
67
How do you iterate through the keys of an object?
by using the for in loop
68
What event is fired when a user places their cursor in a form control?
focus
69
What event is fired when a user's cursor leaves a form control?
blur
70
What event is fired as a user changes the value of a form control?
input
71
What event is fired when a user clicks the "submit" button within a ?
submit
72
What does the event.preventDefault() method do?
prevents the events default action to be run
73
What does submitting a form without event.preventDefault() do?
resets the page
74
What property of a form element object contains all of the form's controls.
elements
75
What property of form a control object gets and sets its value?
value
76
What is an advantage of having your console open when writing a JavaScript program?
it's easier to debug and you can see any errors
77
How do you add an element as a child to another element?
using the addChild method
78
Does the document.createElement() method insert a new element into the page?
no
79
How do you add an element as a child to another element?
using the appendChild method or append method
80
What do you pass as the arguments to the element.setAttribute() method?
element attribute names and value
81
What steps do you need to take in order to insert a new element into the page?
create it, set the properties, and append it
82
What is the textContent property of an element object for?
it holds the text content of the element
83
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
Reusability and flexibility
84
What is the event.target?
the target node of the point of interaction
85
What is the affect of setting an element to display: none?
it removes it from the document flow and hides it
86
What does the element.matches() method take as an argument and what does it return?
it takes in a css selector and returns a boolean
87
How can you retrieve the value of an element's attribute?
by using the getAttribute method
88
At what steps of the solution would it be helpful to log things to the console?
at pretty much every point
89
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?
You would have to add another event listener to that new tab
90
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?
You would have to have a lot of conditionals and over all use very messy code
91
What is JSON?
A text-based data format that follows javacript's object syntax
92
What are serialization and deserialization?
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
Why are serialization and deserialization useful?
to save data and use data
94
How do you deserialize a JSON string into a data structure using JavaScript?
by using the stringify method of the JSON object
95
How to you store data in localStorage?
by using the setItem method of the localStorage object
96
How to you retrieve data from localStorage?
by using the getItem method of the localStorage object
97
What data type can localStorage save in the browser?
JSON
98
When does the 'beforeunload' event fire on the window object?
Just before the page is unloaded/closed
99
What is a method?
A function that is part of an object
100
How can you tell the difference between a method definition and a method call?
A method definition starts with the function keyword | A method call starts with the object name and has an argument list in parenthesis
101
Describe method definition syntax (structure).
functionKey: function optionalName(optionalParameters) {code block}
102
Describe method call syntax (structure).
objectName.Function()
103
How is a method different from any other function?
It is apart of an object
104
What is the defining characteristic of Object-Oriented Programming?
Abstraction
105
What are the four "principles" of Object-Oriented Programming?
Abstraction, Encapsulation, inheritance, and polymorphism
106
What is "abstraction"?
simplifying complex ideas in to simple ones
107
What does API stand for?
Application programming interface
108
What is the purpose of an API?
To allow other people to interact with your program
109
What is this in JavaScript?
An implicit parameter a part of all functions
110
What does it mean to say that this is an "implicit parameter"?
It is included in all functions even if it was never declared
111
When is the value of this determined in a function; call time or definition time?
call time
112
What does this refer to in the following code snippet?
the object literal, character
113
Given the above character object, what is the result of the following code snippet? Why?
'it's-a-me Mario!' because this.firstname is referring to the object character whose firstName property is mario
114
Given the above character object, what is the result of the following code snippet? Why?
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
How can you tell what the value of this will be for a particular function or method definition?
this will be undefined as it is not determined at definition
116
How can you tell what the value of this is for a particular function or method call?
by looking at what ever object's property or method is when it is called
117
What kind of inheritance does the JavaScript programming language use?
prototypal
118
What is a prototype in JavaScript?
An object that delegates its methods and properties to other objects
119
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?
Because the object's prototype contains them
120
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
At it's prototype
121
What does the new operator do?
Creates a blank object, adds __proto__ properties, binds the new instance to this, and returns this
122
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
123
What does the instanceof operator do?
returns a boolean if the instance on the left contains the prototype on the right
124
What is a "callback" function?
A callback function is a function that is passed into another function as an argument
125
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?
with the setTimeout function
126
How can you set up a function to be called repeatedly without using a loop?
with the setInterval function
127
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 (instant)
128
What do setTimeout() and setInterval() return?
a timeoutID
129
What is AJAX?
Ajax is a technique for loading data into part of a page | without having to refresh the entire page.
130
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
131
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
132
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They both inherit from the addeventlistener method
133
What is Array.prototype.filter useful for?
It creates a new array based on filters you put
134
What is Array.prototype.map useful for?
applying transforms to a whole array
135
What is Array.prototype.reduce useful for?
To reduce an array to a single value