JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Store results, quantities, conditionals

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

How do you declare a variable?

A

Keyword var and variable name

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

Use ‘=’

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

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

lowercase names are not the same as capitalizes names

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

math and quantities

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

conditionals

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

Assigning value

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 a new value

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

Different data types. Null always needs to be assigned.

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

So you know what the logged values are for.

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

Give five examples of JavaScript primitives.

A

boolean, number, string, null, undefined

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

Appending strings to make 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

Adding numbers, concatenating 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/appends and assigns the new value

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

What are objects used for?

A

Store related values

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

What are object properties?

A

Keys to access object’s values

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

Describe object literal notation.

A

Curly braces + key, value pairs

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 object.property

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 brackets

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

Why do we log things to the console?

A

To check for expected output of functions and objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is a method?
Function of an object
26
How is a method different from any other function?
Function is stand-alone. Methods belong to objects and are called by first referencing the object.
27
How do you remove the last element from an array?
pop
28
How do you round a number down to the nearest integer?
floor()
29
How do you generate a random number?
random()
30
How do you delete an element from an array?
pop, shift, splice
31
How do you append an element to an array?
push
32
How do you break a string up into an array?
split
33
Do string methods change the original string? How would you check if you weren't sure?
No, strings are immutable. Check MDN.
34
Roughly how many string methods are there according to the MDN Web docs?
Several dozen
35
Is the return value of a function or method useful in every situation?
No
36
Roughly how many array methods are there according to the MDN Web docs?
Several dozen
37
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
38
Give 6 examples of comparison operators.
!==, ===, >=, >,
39
What data type do comparison expressions evaluate to?
boolean
40
What is the purpose of an if statement?
To check a condition
41
Is else required in order to use an if statement?
No
42
Describe the syntax (structure) of an if statement.
If { /* code */ }
43
What are the three logical operators?
&&, ||, !
44
How do you compare two different expressions in the same condition?
Use &
45
What is the purpose of a loop?
To repeat code as many times as needed
46
What is the purpose of a condition expression in a loop?
Determines whether to continue the loop
47
What does "iteration" mean in the context of loops?
Each cycle of the loop
48
When does the condition expression of a while loop get evaluated?
Before each iteration
49
When does the initialization expression of a for loop get evaluated?
Beginning of the loop
50
When does the condition expression of a for loop get evaluated?
Before each iteration
51
When does the final expression of a for loop get evaluated?
After the code block is run.
52
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
53
What does the ++ increment operator do?
Increments the variable it's called on by one
54
How do you iterate through the keys of an object?
for key in object
55
What event is fired when a user places their cursor in a form control?
focus
56
What event is fired when a user's cursor leaves a form control?
blur
57
What event is fired as a user changes the value of a form control?
input
58
What event is fired when a user clicks the "submit" button within a ?
submit
59
What does the event.preventDefault() method do?
Prevents the default action
60
What does submitting a form without event.preventDefault() do?
Data get submitted to server. Form resets. Page reloads.
61
What property of a form element object contains all of the form's controls.
HTMLFormControlCollection
62
What property of form a control object gets and sets its value?
value
63
What is one risk of writing a lot of code without checking to see if it works so far?
You could have more bugs.
64
What is an advantage of having your console open when writing a JavaScript program?
You can see errors.
65
Does the document.createElement() method insert a new element into the page?
no
66
How do you add an element as a child to another element?
appendChild()
67
What do you pass as the arguments to the element.setAttribute() method?
name, value
68
What steps do you need to take in order to insert a new element into the page?
You need to get a node from DOM where you want to insert the new element and use append or appendChild
69
What is the textContent property of an element object for?
Stores the text value
70
Name two ways to set the class attribute of a DOM element.
className = name or | setAttribute('class', name);
71
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
You can reuse it. You can add it as a callback function when an event occurs.
72
What is the event.target?
The element that the event originated from.
73
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubble up
74
What DOM element property tells you what type of element it is?
tagName
75
What does the element.closest() method take as its argument and what does it return?
It takes a selector and returns the closest ancestor that matches the selector.
76
How can you remove an element from the DOM?
remove()
77
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?
Add an eventListener() to the parent and have the callbackfunction work with the event.target.
78
What is the event.target?
The element where the event originated from
79
What is the affect of setting an element to display: none?
It does not display
80
What does the element.matches() method take as an argument and what does it return?
Check is the element matches the selector passed in.
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?
So you can make sure your variables have expected data
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?
You would need to add a listener for each tab.
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?
You would need to have a condition block for each tab.
85
What is JSON?
Text-based data format following JavaScript object format
86
What are serialization and deserialization?
Serialization is the process of turning an object into a series of bytes. Deserialization is turning a series of bytes into an object the program can work with.
87
Why are serialization and deserialization useful?
Serialization is necessary to send data across the network or store data in a compact flat file. Deserialization is necessary to take serialized bytes and output objects that a program can interact with.
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 do you store data in localStorage?
setItem(key, value)
91
How to you retrieve data from localStorage?
getItem(key)
92
What data type can localStorage save in the browser?
primitive data types
93
When does the 'beforeunload' event fire on the window object?
When the page is refreshed or if the user is leaving the page
94
What is a method?
function of an object
95
How can you tell the difference between a method definition and a method call?
Method definition has a code block. Method call has arguments inside parentheses or just parentheses if there's no arguments.
96
Describe method definition syntax (structure).
Method name : function definition block
97
Describe method call syntax (structure).
obj.method()
98
How is a method different from any other function?
method is attached to an object
99
What is the defining characteristic of Object-Oriented Programming?
Pairs variables and functions in one structure
100
What are the four "principles" of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
101
What is "abstraction"?
Separates functionality from implementation. You can use an object and its methods without knowing how it works.
102
What does API stand for?
application programming interface
103
What is the purpose of an API?
Provides a way from different programs/systems/applications to communicate with each other.
104
What is this in JavaScript?
An implicit parameter to the object the method is being called on
105
What does it mean to say that this is an "implicit parameter"?
It is not explicitly defined in the parameters
106
When is the value of this determined in a function; call time or definition time?
call time
107
``` 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); } }; ```
This references nothing until the function is called.
108
Given the above character object, what is the result of the following code snippet? Why? character.greet();
It-s-a-me Mario! Because this references the character variable.
109
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
Undefined. This references the default Window object, which doesn't have firstName variable
110
How can you tell what the value of this will be for a particular function or method definition?
You can't know until the function is called.
111
How can you tell what the value of this is for a particular function or method call?
Look at the object to the left of the dot.
112
What kind of inheritance does the JavaScript programming language use?
Prototypal
113
What is a prototype in JavaScript?
A template that objects can inherit properties from and build off of.
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?
These methods are inherited from the prototype.
115
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
It looks for it in the prototype set in __prototype__ property.
116
What is a "callback" function?
Passing a function as a value, so it can be used when an event triggers.
117
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
118
How can you set up a function to be called repeatedly without using a loop?
setInterval
119
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
120
What do setTimeout() and setInterval() return?
intervalID
121
What does the new operator do?
Instantiates a new object
122
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
123
What is a client?
Client makes a request for data such as a web page or list of information
124
What is a server?
Server sends a response to a request
125
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
126
What three things are on the start-line of an HTTP request message?
HTTP, request type, version of protocol
127
What three things are on the start-line of an HTTP response message?
HTTP, version of protocol, status code
128
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
129
Is a body required for a valid HTTP request or response message?
no
130
What is AJAX?
A way to send and retrieve data from a server
131
What does the AJAX acronym stand for?
Asynchronous Java & XML
132
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
133
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
134
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They're both event objects
135
What is Array.prototype.filter useful for?
To filter results by an expression
136
What is Array.prototype.map useful for?
Apply an operation to all elements of the array
137
What is Array.prototype.reduce useful for?
Combine all elements of the array into one value