JavaScript Flashcards

1
Q

How do you declare a variable?

A

var, let, or const then name

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

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

A

equal ( = ) sign

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

What characters are allowed in variable names?

A

letters, numbers, symbols

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

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

A

“name” is different from “Name”

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

What is the purpose of a string?

A

text content

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

What is the purpose of a number?

A

math stuff

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

What is the purpose of a boolean?

A

determine true or false

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

What does the = operator mean in JavaScript?

A

is assigned to

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

How do you update the value of a variable?

A

variable name = ‘new value’

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

What is the difference between null and undefined?

A

null - placed there on purpose, doesn’t exist
undefined - there’s nothing assigned to a variable

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

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

A

to keep track of what the logs are for

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

Give five examples of JavaScript primitives.

A

string, number, boolean, null, undefined

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

What is string concatenation?

A

putting two strings together

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

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

A

addition or concatenating strings

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

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

A

adding something to the variable, then updating that variable

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

adding something to the variable, then updating that variable

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

What are objects used for?

A

key, value lists

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

What are object properties?

A

variables specifically for objects

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

Describe object literal notation.

A

variable name, the curly-braces surrounding key-value pairs, separated by commas

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

delete operator then obj.key

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

lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
variable name, square bracket, then values separated by commas
26
How are arrays different from "plain" objects?
arrays' keys are their index numbers
27
What number represents the first index of an array?
0
28
What is the length property of an array?
get how many items are in the array
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
a set of statements that performs a task
31
Describe the parts of a function definition.
function keyword, optional function name, optional parameters (separated by a comma), function body, optional return statement
32
Describe the parts of a function call.
function name with parenthesis with optional arguments
33
function name with parenthesis with optional arguments
function call - function name and parenthesis (optional arguments)
34
function call - function name and parenthesis (optional arguments)
parameter - used in function definition
35
Why are function parameters useful?
can use keyword for a different things, instead of specifying the item again and again
36
What two effects does a return statement have on the behavior of a function?
1. function produces a value that can be used 2. prevents more code in the block from running
37
Why do we log things to the console?
to inform developers what the code is doing
38
What is a method?
a function in an object
39
How is a method different from any other function?
it's specifically attached to an object
40
How do you remove the last element from an array?
.pop()
41
How do you round a number down to the nearest integer?
Math.floor()
42
How do you generate a random number?
Math.random()
43
How do you delete an element from an array?
.splice(startIndex, # of items to remove)
44
How do you append an element to an array?
.push()
45
How do you break a string up into an array?
.split()
46
Do string methods change the original string? How would you check if you weren't sure?
no, strings are immutable use console.log(string) to check
47
Roughly how many string methods are there according to the MDN Web docs?
30+
48
Is the return value of a function or method useful in every situation?
no
49
Roughly how many array methods are there according to the MDN Web docs?
38+
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
Give 6 examples of comparison operators.
===, !==, less than, greater than, less than or equal to, greater than or equal to
52
What data type do comparison expressions evaluate to?
boolean
53
What is the purpose of an if statement?
check if the statement is truthy then it runs a block of code, if not, it does something else
54
Is else required in order to use an if statement?
no
55
Describe the syntax (structure) of an if statement.
'if' keyword (statements) { code block to run }
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
if (something || something else)
58
What is the purpose of a loop?
to repeat a block of code until a condition is met
59
What is the purpose of a condition expression in a loop?
to let code know when to start and stop
60
What does "iteration" mean in the context of loops?
a run through of a code (one loop)
61
When does the condition expression of a while loop get evaluated?
before the start run of every loop
62
When does the initialization expression of a for loop get evaluated?
once, at the very beginning
63
When does the condition expression of a for loop get evaluated?
before each loop runs
64
When does the final expression of a for loop get evaluated?
after each loop runs
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?
adds 1 to the variable
67
How do you iterate through the keys of an object?
for (var key in obj)
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 form?
submit
72
What does the event.preventDefault() method do?
prevents browser from reloading the page with the form's values in the URL
73
What does submitting a form without event.preventDefault() do?
reloads 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 one risk of writing a lot of code without checking to see if it works so far?
hard to debug, would have to figure out which part isn't working
77
What is an advantage of having your console open when writing a JavaScript program?
you can see if the code is working properly immediately
78
What is the event.target?
whatever element you applied the listener to that you focused/clicked on The DOM element that you directly interacted with, that triggered the event
79
What is the effect of setting an element to display: none?
hidding the element
80
What does the element.matches() method take as an argument and what does it return?
argument - selector returns a boolean
81
How can you retrieve the value of an element's attribute?
.getAttribute
82
At what steps of the solution would it be helpful to log things to the console?
every step!
83
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?
create individual event listeners
84
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?
using hard coding
85
What is JSON?
a text-based data format following JavaScript object syntax; JSON exists as a string — useful when you want to transmit data across a network
86
What are serialization and deserialization?
Serialization - process where an object or data structure is translated into a format suitable for transferral over a network, or storage Deserialization - the reverse process: turning a stream of bytes into an object in memory
87
Why are serialization and deserialization useful?
serialization allows us to convert the state of an object into a byte stream, which then can be saved into a file on the local disk or sent over the network to any other machine. And deserialization allows us to reverse the process, which means reconverting the serialized byte stream to an object again.
88
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
89
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
90
How to you store data in localStorage?
.setItem()
91
How to you retrieve data from localStorage?
.getItem()
92
What data type can localStorage save in the browser?
string
93
When does the 'beforeunload' event fire on the window object?
reloading page, clicking to different page, closing tab / browser
94
What is a method?
a function which is a property of an object
95
How can you tell the difference between a method definition and a method call?
method definition - function is saved as a property method call - name of object. method name ()
96
Describe method definition syntax (structure).
method name: function
97
Describe method call syntax (structure).
objectName.methodName()
98
How is a method different from any other function?
nothing really; a method is attached to an object and can only be called through the object
99
What is "abstraction"?
being able to work with (possibly) complex things in simple ways
100
What does API stand for?
application programming interface
101
What is the purpose of an API?
give programmers a way to interact with a system in a simplified, consistent fashion
102
What is the purpose of an API?
give programmers a way to interact with a system in a simplified, consistent fashion
103
What is this in JavaScript?
the object to the left of the dot at call time
104
When is the value of this determined in a function; call time or definition time?
call time
105
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); } };
nothing. this is not being called
106
Given the above character object, what is the result of the following code snippet? Why?
"It's-a-me, Mario!"
107
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
"It's-a-me, undefined!" the run time at hello has nothing at the left of the dot
108
How can you tell what the value of this will be for a particular function or method definition?
this will be the object the method is a property of
109
How can you tell what the value of this is for a particular function or method call?
unkown
110
How can you tell what the value of this is for a particular function or method call?
object on the left side of the dot
111
What does it mean to say that this is an "implicit parameter"?
not explicitly defined, this is a value that changes in every function call
112
What kind of inheritance does the JavaScript programming language use?
prototype-based (or prototypal) inheritance
113
What is a prototype in JavaScript?
an object that contains properties and (predominantly) methods that can be used by other objects
114
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?
they borrow methods from the prototype object
115
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
__proto__ property
116
What does the new operator do?
1. Creates a blank, plain JavaScript object. 2. Adds a property to the new object (__proto__) that links to the constructor function's prototype object 3. Binds the newly created object instance as the this context 4. Returns this if the function doesn't return an object.
117
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
118
What does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object; returns a boolean value
119
What is a "callback" function?
a function passed into another function as an argument
120
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?
setTimeout() setInterval()
121
How can you set up a function to be called repeatedly without using a loop?
setInterval()
122
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
123
What do setTimeout() and setInterval() return?
timerID
124
What is AJAX?
a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest; allows you to update parts of the DOM of an HTML page instead without the need for a full page refresh
125
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
126
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest object
127
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
128
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
inheritance
129
What is Array.prototype.filter useful for?
when you want a new array with only elements that passes a specific test
130
What is Array.prototype.map useful for?
when you want a new array with modified elements
131
What is Array.prototype.reduce useful for?
when you want a single output from a chunk of data