Javascript Flashcards

1
Q

What is the purpose of a variable?

A

to provide a place to store data to access

in the future

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

How do you declare a variable?

A

var variable = value

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

by using =, with variable on left side and value on right

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, dollar sign, underscore, numbers(but cannot start with number)

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

that uppercase and lowercase are entirely separate entities

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 non-numerical values + data

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 mathematical operations + numerics

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 the true/false values and make decisions

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

to assign

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 changing value after the = sign

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 = purposefully put by human programmer
undefined = organic javascript
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

to make it easier to debug

ALWAYS label

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

numeric

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

What is string concatenation?

A

combining two string using concatenation operator (+)

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
  1. to concatenate

2. to add

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

takes current value of variable and adds new value to variable and returns value of it

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

What are objects used for?

A

useful for storing multiple pieces of data that are related to each other

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

What are object properties?

A

names of the related pieces of objects

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

Describe object literal notation.

A

a set of curly braces, with keys and values within them

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 operator

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 square bracket notation

ALWAYS use dot notation

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

What are arrays used for?

A

making lists of related data of the same type

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

Describe array literal notation

A

brackets [ } with commas separating values

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

Arrays have numbered indexes,

objects have alpha numerical indexes

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

how long the array is /

how many pieces of data are in it

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

the length property of an array - 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

an expression that gives repeatability to a code block

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

function keyword, optional name, parameters, function code block, optional return statement

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

function name, parenthesis, data in parenthesis

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

function call = no keyword, and no code block

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

parameters exist when defining a function,

arguments happen when calling a function

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

Why are function parameters useful?

A

they provide re-usability

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
  1. It stops the function

2. spits out the return value of 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

to spit out the current value of things

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

What is a method?

A

a function stored as a property on 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

methods always need dot (.) before they’re called,

functions can be called by themselves

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

.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

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

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

.splice() method

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

.push() method

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

.split() method

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, and you can check with console log/MDN

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

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

A

Around fifty, A lot

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

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

A

Not always

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

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

A

A lot

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

Give 6 examples of comparison operators.

A

strictly equal, less than or equal to, more than, more than or equal to, not equal

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 true/false

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

What is the purpose of an if statement?

A

let functions make decisions based on conditions

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

Describe the syntax (structure) of an if statement.

A

keyword if, condition in parenthesis, conditional code block

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

What are the three logical operators?

A

&& - and
|| - or
! - not

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

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

A

using && - and or || - or

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

What is the purpose of a loop?

A

to keep repeating a chunk of code until a certain condition is met

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

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

A

to help stop the loop

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

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

A

each time the code block runs

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

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

A

in the beginning, once

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

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

A

after the final expression, and right before the code block

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

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

A

right after each iteration

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

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

What does the ++ increment operator do?

A

adds one to whatever the value is

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

How do you iterate through the keys of an object?

A

for ..in loops

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

Why do we log things to the console?

A

To inspect their value and make sure it’s up to par

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

What is a “model”?

A

A representation of something

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

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

A

An object model of the HTML document

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

What is a DOM tree?

A

A JavaScript object for an HTML element that holds all of its children and children’s contents, values, text content and attributes

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

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

A

GetElementByID, querySelector

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

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

A

To go back and adjust it later

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

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

A

Console.dir

77
Q

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

A

The HTML needs to load before the script

78
Q

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

A

Returns the first element it finds and takes css selectors as arguments as strings

79
Q

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

A

Arguments = string of css selector

Returns node list (array type of data)

80
Q

Why do we log things to the console?

A

To check if the right value is returned

81
Q

What is the purpose of events and event handling?

A

To create a reaction in response to something happening

82
Q

Are all possible parameters required to use a JavaScript method or function?

A

No

83
Q

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

A

AddEventListener

84
Q

What is a callback function?

A

A function definition being passed to another function as a value

85
Q

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

A

An object with a huge amount of properties with data explaining event

86
Q

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

A

Where the event EXACTLY occurs, more information available through console.log

87
Q

What is the difference between these two snippets of code?

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

A

One of the functions is being called and returns the return

The other one uses function DEFINITION

88
Q

What is the className property of element objects?

A

a property stored on a DOM Element object that stores the class attributes of that object

89
Q

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

A

the className property with a value assigned to it

90
Q

What is the textContent property of element objects?

A

allows to set or update text content of HTML element

91
Q

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

A

using .textContent and new string in parenthesis

92
Q

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

A

No

93
Q

Would a DOM assignment be simpler or more complicated if a variable wasn’t used to keep track of the number of clicks?

A

would be simpler with variable

94
Q

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

A

so that you can use it later and to not mix languages with each other

95
Q

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

A

“Focus”

96
Q

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

A

“Blur”

97
Q

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

A

“Input”

98
Q

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

A

“Submit”

99
Q

What does the event.preventDefault() method do?

A

Prevents default browser behavior for the element for that event

100
Q

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

A

It Acts as it normally would

101
Q

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

A

The .elements property

102
Q

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

A

The value property

103
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

If it doesn’t work, you don’t know where it’s broken

104
Q

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

A

So you know what goes right, wrong and in general so you know what goes on

105
Q

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

A

No, it just creates one

106
Q

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

A

.appendChild

107
Q

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

A

First string with the name of attribute, then second string as the value of the attribute

108
Q

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

A

.CreateElement method and append method on another element

109
Q

What is the textContent property of an element object for?

A

It stores the text content of an HTML element to make new, or retrieve

110
Q

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

A

className property and setAttribute method

111
Q

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

A

Easier to test, and easier to re-use

112
Q

What is the event.target?

A

The element where the event occurred

113
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

Event bubbling

114
Q

What DOM element property tells you what type of element it is?

A

tagName

115
Q

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

A

Takes a CSS selector string as an argument, and returns the ancestor of the element being called

116
Q

How can you remove an element from the DOM?

A

.remove() method

117
Q

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?

A

Add an eventListener to the parent

118
Q

What is the event.target?

A

The element on which the event took place

119
Q

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

A

It hides and removes the element from the document flow completely, yielding it’s space to visible elements

120
Q

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

A

$element.matches() takes a string containing a CSS selector as its argument and returns a Boolean indicating whether or not it matched the selector

121
Q

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

A

$element.getAttribute(‘attribute name’)

122
Q

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

A

Every step!

123
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 an event listener to each of the tab elements individually

124
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 write out the code to hide and reveal views based on the condition of which tab was clicked

125
Q

What is JSON?

A

JSON is a format for converting JavaScript objects into strings of text.

126
Q

What are serialization and deserialization?

A

Serialization is the process of converting an object in memory into a stream of bytes.

Deserialization is converting the bytes to an object in memory

127
Q

Why are serialization and deserialization useful?

A

They’re useful for transmitting JavaScript objects and the data they contain to other platforms that may not support JavaScript, but can read JSON strings.

128
Q

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

A

JSON.stringify(object)

129
Q

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

A

JSON.parse(JSONstring)

130
Q

How do you store data in localStorage?

A

localStorage.setItem(‘name’, ‘value’)

131
Q

How do you retrieve data from localStorage?

A

localStorage.getItem(‘name’)

132
Q

What data type can localStorage save in the browser?

A

Strings. Other data types are converted to Strings, and Objects must be stringified first.

133
Q

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

A

Before the page get unloaded

ie:
closed, refreshed, or clicked away from

134
Q

What is a method?

A

A function stored as a value for a property of an object

135
Q

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

A

Call would include object.method()

Definition includes property with function
Ie:
Property: function()

136
Q

Describe method definition syntax (structure).

A

Function definition that is being stored as property of an object

137
Q

Describe method call syntax (structure).

A

Object.method(argument)

138
Q

How is a method different from any other function?

A

A method NEEDS an object.

Functions are independent.

139
Q

What is the defining characteristic of Object-Oriented Programming?

A

That an object can contain both data and methods to work together

140
Q

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

A

Abstraction, inheritance, polymorphism, incapsulation

141
Q

What is “abstraction”?

A

Taking complex problems and making them accessible

142
Q

What does API stand for?

A

Application Programming Interface

143
Q

What is the purpose of an API?

A

To communicate between different pieces of software

144
Q

What is this in JavaScript?

A

“This” is an implicit parameter that returns the value of the object from which the function was called

145
Q

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

A

That it’s given to the function even if you don’t see the parameter listed

146
Q

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

A

Call time

147
Q

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);
  }
};
A

Nothing

148
Q
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};

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

character.greet();

A

It’s a me mario

149
Q
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};

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

var hello = character.greet;
hello();
A

It’s a me undefined

150
Q

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

A

You can’t.

151
Q

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

A

By the object to the left of the dot

152
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal Inheritance

153
Q

What is a prototype in JavaScript?

A

An object that a bunch of objects can build off of

154
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 they’re grabbing it from the prototype

155
Q

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

A

On the prototypes

156
Q

What does the new operator do?

A
  1. Lets you create an object
  2. Adds property to new object proto
  3. Binds new object as this
  4. Returns “this” if function doesn’t return object
157
Q

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

A

Prototype property

158
Q

What does the instanceof operator do?

A

Checks whether or not an object is in the same prototypal chain

159
Q

What is a “callback” function?

A

Functions being passed around as values

160
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

Applying a delay with setTimeout()

161
Q

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

A

setInterval()

162
Q

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

A

0

163
Q

What do setTimeout() and setInterval() return?

A

A number id to represent the interval

164
Q

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

A

A codeblock is code between two curly braces

Ie:
Function codeblocks, conditional codeblocks

165
Q

What does block scope mean?

A

Located within codeblock

166
Q

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

A

What the written code is applicable to

167
Q

What is the difference between let and const?

A

Let can be reassigned, const cannot

168
Q

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

A

Because you’re changing the contents, not reassigning the variable itself

169
Q

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

A

If you need to reassign the variable, use let

Otherwise use const

170
Q

What is the syntax for writing a template literal?

A

High quotation marks to initiate and close: ‘ ‘

Along with ${variable} to reference any variables within template literal

171
Q

What is “string interpolation”?

A

Ability to embed variables within strings

172
Q

What is destructuring, conceptually?

A

Assigning properties to individual variables

173
Q

What is the syntax for Object destructuring?

A

Variable declaration, curly braces, property names, right side of = would be object being destructured.

174
Q

What is the syntax for Array destructuring?

A

Variable declaration, square brackets, variables for elements at indexes, commas to separate and array being destructured on right side of =

175
Q

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

A

Placement of brackets in respect to assignment operator (left or right of object/array)

176
Q

What is the syntax for defining an arrow function?

A

Variable name, assignment operator, parameter(more than one needs parenthesis), => operator and codeblock

177
Q

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

A

It will return expression without curly braces but needs curly braces for multiple lines of code

178
Q

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

A

Based on surrounding scope that arrow function was defined in

179
Q

What are the three states a Promise can be in?

A

Pending, fulfilled, rejected

180
Q

How do you handle the fulfillment of a Promise?

A

Then() method

181
Q

How do you handle the rejection of a Promise?

A

Catch() method

182
Q

What is Array.prototype.filter useful for?

A

Returning a list of the filter criteria

183
Q

What is Array.prototype.map useful for?

A

To apply something to every element in the array, and receive a new array with changes values for the whole original array

184
Q

What is Array.prototype.reduce useful for?

A

Combining elements of an array into a single value

185
Q

What is “syntactic sugar”?

A

Syntax that makes things easier to read, write, and understand

186
Q

What is the typeof an ES6 class?

A

Function

187
Q

Describe ES6 class syntax.

A

Class declaration, class body, class name, optional constructor function

188
Q

What is “refactoring”?

A

Rewriting the same code with different syntax that accomplishes the same actions

189
Q

How are ES Modules different from CommonJS modules?

A
  1. ES modules are built into JS
  2. Syntactically different
  3. No need for variable assignments in ES6