Javascript Flashcards

1
Q

What is the purpose of variables?

A

To temporarily store a value in a program

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 followed by a value

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(but not first), underscores, and dollar signs.

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

each letter, undercase and lowercase, has a different ASCII value.

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 words and shit

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 number

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 either a true or false value that will determine the outcome of certain decisions in your program.

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 that will assign a value to a variable.

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

by initializing it with no var keyword.

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 assigned blank value while undefined is a not yet defined value.

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

it makes code reading easier

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

Give five examples of JavaScript primitives.

A

number, string, boolean, 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

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 strings with an addition sign

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

both adds numbers and concatenates 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

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

it adds the value, or expression, to the right of the equals sign to value of the variable to the left and then assigns that value to the variable.

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

What are objects used for?

A

to store related data and put together a type of model of some sort.

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

What are object properties?

A

variables inside of an object

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

Describe object literal notation.

A

after var assignment opening curly brace followed by the key of the property then a colon then the value of that property. Each of those properties are separated by commas. End with a closing curly brace.

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

the delete keyword and the 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 and 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

for lists that don’t need to be ordered

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

Describe array literal notation.

A

after var assignment opening bracket then values separated by commas then closing bracket

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

they use the index system instead of 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

array.length and it gives the length of the array.

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

array.length - 1.

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 set of code that is declared to complete a specific task

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 function key word, the name of the function, parameters if any, then the code block

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 function name followed by arguments if any then a semi colon.

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 is when a function is to be used, the function definition is when a function is to be declared.

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 the place holder variable in the function definition that will replaced when the function is called by the arguments listed in the function call. arguments are in the function call.

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

Why are function parameters useful?

A

the way to provide data for the functions and give different results so that the functions can be used in a variety of cases.

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

it both returns data to the function then stops the function.

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 purposes to catch mistakes.

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

What is a method?

A

a function attached to 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 directly modifies the thing it is attached to. other than that they are the same

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

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

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

A

using the math object with the floor method

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

How do you generate a random number?

A

using the math object with the random method

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

How do you delete an element from an array?

A

using the splice method on your array.

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

How do you append an element to an array?

A

using the push method on your array

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

How do you break a string up into an array?

A

using the split method with a string of a single space as your argument

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

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

A

no they only affect the return value. You can check by logging the original string to the console.

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, you don’t need to use it if you don’t have to.

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

Give 6 examples of comparison operators.

A

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

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

What is the purpose of an if statement?

A

to give multiple paths for a conditional statement

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

Describe the syntax (structure) of an if statement.

A

the key word if followed by the conditional expression and then the code block

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

What are the three logical operators?

A

&&, ||, !

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

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

A

with logical operators.

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

What is the purpose of a loop?

A

to repeat a certain section of code if necessary

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

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

A

to give that loop an exit route.

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

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

A

how many times the loop runs

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

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

A

before each iteration

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

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

A

its the very first step

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

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

A

before each loop iteration runs

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

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

A

after the loop code block is excecated

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

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

What does the ++ increment operator do?

A

adds 1 and assigns it to the variable

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

How do you iterate through the keys of an object?

A

a for in loop

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

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

A

the HTML document

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

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

A

Objects in the JavaScript language

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

What is a DOM Tree?

A

a tree representation of an HTML document

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

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

A

getElementByID, and querySelector

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

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

A

querySelectorAll

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

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

A

because if used more than once it doesn’t have to retrieve the return address of a DOM query multiple times.

72
Q

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

A

dir

73
Q

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

A

so all the HTML could run first

74
Q

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

A

takes a string of the tag name, class, or id as a CSS selector. It returns the first element it finds that matches that selector

75
Q

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

A

takes a string of a CSS selector. It returns a node list of all the elements under that selector

76
Q

What is the purpose of events and event handling?

A

It is a way for the user to interact with the webpage and potentially change the style of the page and many other things.

77
Q

What do [] square brackets mean in function and method syntax documentation?

A

its optional

78
Q

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

A

addEventListener

79
Q

What is a callback function?

A

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

80
Q

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

A

an event object built by JavaScript.

81
Q

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

A

It is the element object from where the event originated from. you could console.log the event object and check, or look it up in MDN

82
Q

What is the difference between these two snippets of code?

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

A

the first waits to execute the function until that element node is clicked, while the second one executes before the webpage is loaded.

83
Q

What is the className property of element objects?

A

gets and sets the value of the class attribute of the specified element.

84
Q

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

A

by using the className property on the event variable and setting it equal to the class name in a string.

85
Q

What is the textContent property of element objects?

A

represents the text content of the node and its descendants.

86
Q

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

A

by using the textContent property on the event variable and setting it equal to the text you desire

87
Q

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

A

no

88
Q

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

A

It cuts back execution time because JavaScript doesn’t constantly have to fetch all the elements it needs to use, it just uses the stored addresses in the variable assigned.

89
Q

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

A

the focus event

90
Q

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

A

the blur event

91
Q

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

A

the input event

92
Q

What does the event.preventDefault() method do?

A

tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.

93
Q

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

A

it refreshes the page

94
Q

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

A

elements

95
Q

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

A

value

96
Q

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

A

You can see when and where mistakes happen

97
Q

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

A

the submit event

98
Q

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

A

no it just creates an element

99
Q

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

A

appendChild method

100
Q

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

A

the attribute name and the value

101
Q

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

A

creating the element, query the element you want to append it to, then append the element you created to the node you queried.

102
Q

What is the textContent property of an element object for?

A

to either retrieve the text, or assign the element some text value

103
Q

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

A

use the setAttribute method, or assign a new name to the className property.

104
Q

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

A

it is both reusable and condenses code.

105
Q

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

A

you can no longer see nor interact with said element and it is no longer in document flow.

106
Q

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

A

it takes a string of a CSS selector and returns a boolean of whether or not the selector is the same value

107
Q

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

A

by using the getAttribute method

108
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

using an eventListener on every node in that tab that needs to be added

109
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

comparing each class name at the index starting from 0 to the length of the node list one by one manually.

110
Q

What is JSON?

A

JSON is a text-based data format following JavaScript object syntax

111
Q

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a stream of bytes Deserialization is the reverse process: turning a stream of bytes into an object in memory.

112
Q

Why are serialization and deserialization useful?

A

You can do stuff like store it on disk or send it over the network.

113
Q

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

A

using the JSON.stringify method with the data as the argument

114
Q

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

A

with the JSON.parse method with the JSON string as the argument.

115
Q

How to you store data in localStorage?

A

by using the setItem method on the localStorage object

116
Q

How to you retrieve data from localStorage?

A

by using the getItem method on the localStorage object

117
Q

What data type can localStorage save in the browser?

A

only strings or null

118
Q

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

A

right before the webpage is either reloaded or exited.

119
Q

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

A

method definitions use the function keyword and are ended with a code block for defining the function. method calls use that method of the property it is attached to followed by parentheses and arguments in that if needed.

120
Q

Describe method definition syntax (structure).

A

method definitions have the function keyword, followed by the function name, followed by any parameters within parentheses, followed by the definition block

121
Q

Describe method call syntax (structure).

A

method calls are attached to the property it is used on and are followed by parameters incased in parentheses if any.

122
Q

How is a method different from any other function?

A

a method can be used on objects while functions cannot.

123
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

124
Q

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

A

Abstraction, Encapsulation, Inheritance, and Polymorphism.

125
Q

What is “abstraction”?

A

Being able to work with (possibly) complex things in simple ways. Basically making complex problems easier to tackle.

126
Q

What does API stand for?

A

Application Programming Interface

127
Q

What is the purpose of an API?

A

It gives programmers a way to interact with a system in a simplified, consistent fashion

128
Q

What is this in JavaScript?

A

this is an implicit parameter of all JavaScript functions.

129
Q

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

A

it means that the values change based on the context

130
Q

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

A

during the function call

131
Q

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

A

you cannot

132
Q

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

A

by the object that it is being used on

133
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype based

134
Q

What is a prototype in JavaScript?

A

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

135
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

prototypes

136
Q

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

A

__proto__ object

137
Q

What does the new operator do?

A

creates a blank object, adds a property to the new object (__proto__) that links to the constructor function’s prototype object, binds the newly created object instance as the this context, and returns this if the function doesn’t return an object.

138
Q

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

A

the prototype property

139
Q

What does the instanceof operator do?

A

tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

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

141
Q

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

A

setInterval function

142
Q

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

A

0ms

143
Q

What do setTimeout() and setInterval() return?

A

a timeoutID to later use with clearTimeout functions and shit

144
Q

What is AJAX?

A

Ajax is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.

145
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

146
Q

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

A

the XMLHttpRequest object

147
Q

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

A

load event

148
Q

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

A

through the power of PROTOTYPES

149
Q

What is a code block? What are some examples of a code block?

A

a code block is a set of instructions contained within a set of curly braces. { console.log(‘you are super cute’) }

150
Q

What does block scope mean?

A

the accessible code within that code block

151
Q

What is the scope of a variable declared with const or let?

A

it can be used within the code block it was declared in

152
Q

What is the difference between let and const?

A

let is mutable while const is not mutable

153
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

because the const value is holding the address of the array, not to contents inside of it.

154
Q

How should you decide on which type of declaration to use?

A

if you want the value of the variable to change or not.

155
Q

What is the syntax for writing a template literal?

A

using backticks instead of single or double quotes for strings

156
Q

What is “string interpolation”?

A

adding expressions inside of strings.

157
Q

What is destructuring, conceptually?

A

assigning properties to variables

158
Q

What is the syntax for Object destructuring?

A

const { property1, property2 } = object;

159
Q

What is the syntax for Array destructuring?

A

const [property1, property2 ] = array;

160
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

the “assignment” of the object name is after the object or array literal.

161
Q

What is the syntax for defining an arrow function?

A

parameters , arrow syntax , definition

162
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

you don’t need a return statement

163
Q

How is the value of this determined within an arrow function?

A

in an ES5 regular function, the value of this is determined at call time. when it is called, this is the object to the left of the method. If no object it is the window object. to sum up, the value of this in arrow functions is determined at definition time, while in ES5 functions, the value of this is defined at execution time.

164
Q

What method is available in the Node.js fs module for writing data to a file?

A

fs.writeFile( );

165
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

166
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

167
Q

How do you handle the fulfillment of a Promise?

A

by using the then method of the Promise object

168
Q

How do you handle the rejection of a Promise?

A

by using the catch method of the Promise object

169
Q

What is the typeof an ES6 class?

A

an object

170
Q

Describe ES6 class syntax.

A

first start with the

171
Q

What is “refactoring”?

A

changing the way how code is written, not tampering with the functionality, but making its readability easier and such.

172
Q

What does fetch() return?

A

it returns a promise containing a response

173
Q

What is the default request method used by fetch()?

A

GET?

174
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

as the method property of the init object passed as a second optional argument in the fetch function

175
Q

When does React call a component’s componentDidMount method?

A

immediately after render

176
Q

Name three React.Component lifecycle methods.

A

componentDidMount, componentUpdate, componentWillMount

177
Q

How do you pass data to a child component?

A

as a prop