JavaScript Flashcards

1
Q

What is the purpose of variables?

A

a place to store data for 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 name” = 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

with an equal sign

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(not first character), $, _

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

letter casing creates unique variables

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

basically text content

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 count and do math

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 show true/false, on/off

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 means to assign value

it’s an 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

“variable name” = 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

null is null, undefined means no assigned 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

for ease of use later on

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

number operator

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

What is string concatenation?

A

combining strings together

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

addition or concatination

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 left operand to right operand then assigns result to left operand

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

What are objects used for?

A

grouping data to represent an actual thing

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

{ property: property name,

property name};

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

making lists of data

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

Describe array literal notation.

A

var ‘name’ = [value, value, value]

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 store in an ordered list with solely a data-type, no property name required

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 ever many items are currently inside of it -1

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

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

a set of statements that perform a repeatable 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

keyword, name, (parameters), {function block}, return keyword

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(list of arguments)

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

parameters/arguments
code block in def, not in call
call will always have ( )
function keyword in def not call

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 are placeholders in a definition

arguments become the value of that placeholder

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

Why are function parameters useful?

A

they can help describe what kind of data will be used later as the argument

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

a return replaces a function call

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 confirm the result of an action

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

What is a method?

A

a function which is the property of 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

JS functions are not objects so a method is a reference to a function

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

array.pop( )

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

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

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

array.splice(start, delete)

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

array.push( )

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

string.split( )

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

they don’t, check by just doing it and console.logging the original string

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

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

Booleans

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

make a decision

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

if (condition) { what happens}

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 a && or || operator

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

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

A

when to stop the loop

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

What is the purpose of a loop?

A

run a block multiple times

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

single run of the code-block

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 code block runs

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

before the loop begins, only once

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

after the initialization, before each iteration

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

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

increments the value of a var by one and substitutes that value to the var

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

for in loop

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

Why do we log things to the console?

A

to make sure funcitons/methods call correctly and verifying input to outputs

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

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

A

the html document thats been linked to the JS document

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

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

A

a datatype used to represent and recreate the document it’s referencing to make changes on

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

What is a DOM Tree?

A

a representative chunk of a page built as JS objects

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

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

A

querySelector, getElementbyId

72
Q

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

A

querySelectorAll, getElementByClass

73
Q

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

A

to access the data late without searching for it again

74
Q

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

A

console.dir

75
Q

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

A

so the HTML will load first

76
Q

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

A

takes a string as argument with a CSS selector and returns the first instance of the contents of that string

77
Q

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

A

takes a string with a CSS selector as argument, returns node-list of all instances of that content.

78
Q

What is the purpose of events and event handling?

A

so that when the user or browser does something, there is a response from the code.

79
Q

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

A

no

80
Q

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

A

addEventListener

81
Q

What is a callback function?

A

a function being passed as an argument in another function

82
Q

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

A

an object with all the data about the event that just occurred

83
Q

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

A

the HTML element where the event originated from. If you wanted to learn more you could console log the event.target

84
Q

What is the difference between these two snippets of code?

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

A

the first one is being used as a callback, the second one is an immediate function call

85
Q

What is the className property of element objects?

A

allows to get and set the properties of an object

86
Q

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

A

element.classname = ‘newclassname’

87
Q

What is the textContent property of element objects?

A

allows to get and set the classname value

88
Q

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

A

element.textContent = ‘new content’

89
Q

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

A

no?

90
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

no

91
Q

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

A

cut out the middle man. Keeping data in one place makes it easy to track

92
Q

What does the event.preventDefault() method do?

A

prevent the action of whatever event you’re using

93
Q

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

A

no, it creates a new element node that WILL be inserted

94
Q

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

A

appendChild method

95
Q

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

A

(attribute name, value)

96
Q

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

A

assign createElement to a new variable, append that variable to another existing element

97
Q

What is the textContent property of an element object for?

A

adding text nodes to elements

98
Q

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

A

setAttribute method, element.className =

99
Q

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

A

makes it reusable. saves a lot of time

100
Q

What is the event.target?

A

the origin point of an event listener

101
Q

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

A
102
Q

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

A

event.target.tagName

103
Q

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

A

takes a CSS selector and returns the nearest ancestor element with that selector

104
Q

How can you remove an element from the DOM?

A

element.remove()

105
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 event listener to the parent and identify it by its tagName

106
Q

What is the event.target?

A

the origin element of an assigned event

107
Q

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

A

hides the element from the viewable page

108
Q

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

A
109
Q

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

A

with a css selector in the form of a string

110
Q

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

A

at every step

111
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’d have to write a condition for every possible view

112
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
113
Q

What is a method?

A

a method is a function that is part of an object

114
Q

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

A

definition includes code block and full syntax, call just has arguments.

115
Q

Describe method definition syntax (structure).

A

method name: function (parameters) {code block}

116
Q

Describe method call syntax (structure).

A

objName.method()

117
Q

How is a method different from any other function?

A

its stored in an object

118
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

119
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

120
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways

121
Q

What does API stand for?

A

application programming interface

122
Q

What is the purpose of an API?

A

a set of tools to allow access to functionality easily

123
Q

What is this in JavaScript?

A

refers to the object ‘this’ is being worked with

124
Q

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

A

it has value without having one assigned by a function

125
Q

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

A

call time

126
Q

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

A

we can’t know

127
Q

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

A

whats on the left of the dot in the method/function call

128
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inheritance

129
Q

What is a prototype in JavaScript?

A

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

130
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

through prototypal inheritance

131
Q

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

A

in the prototype

132
Q

What does the new operator do?

A

lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

133
Q

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

A

prototype

134
Q

What does the instanceof operator do?

A

tests to see if something if a prototype constructor of a given object

135
Q

What is a “callback” function?

A
136
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()

137
Q

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

A

setInterval()

138
Q

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

A

0 milliseconds

139
Q

What do setTimeout() and setInterval() return?

A

a numeric ID for the created timer that can be passed to clearInterval/clearTimeout

140
Q

What is AJAX?

A

an asynchronous processing model that requests data without reloading the whole webpage

141
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

142
Q

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

A

XMLHttpRequest

143
Q

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

A

load

144
Q

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

A

because of prototypal inheritance

145
Q

What does block scope mean?

A

anything inside of the code block, not outside

146
Q

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

A

the block it’s in

147
Q

What is the difference between let and const?

A

let can be reassigned, const can not

148
Q

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

A

because the const is pointing to a mutable data location, you aren’t changing the pointer location

148
Q

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

A

do you want to change it or not

149
Q

What is the syntax for writing a template literal?

A

backticks, variables use ${}

text ${variable}

150
Q

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions.

151
Q

What is destructuring, conceptually?

A

taking pieces of an obj or array and turning it into multiple variables

152
Q

What is the syntax for Object destructuring?

A

const {name, name} = source

153
Q

What is the syntax for Array destructuring?

A

const [name, name , , name] = source

154
Q

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

A

what’s on the left of the assignment operator

155
Q

What is the syntax for defining an arrow function?

A

variable = (perameters) => {code}

156
Q

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

A

it just returns the result of whatever code is there

157
Q

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

A

in a normal function, this is defined at call time, in an arrow function it’s defined at the time of definition

158
Q

What is the JavaScript Event Loop?

A

monitors the callstack and waits until the callstack is empty then pushes the top item from the task-que into the callstack

159
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A
160
Q

What are the three states a Promise can be in?

A

pending
fulfilled
rejected

161
Q

How do you handle the fulfillment of a Promise?

A

.then

162
Q

How do you handle the rejection of a Promise?

A

.catch

163
Q

What is Array.prototype.filter useful for?

A

creating a new array while excluding some things

164
Q

What is Array.prototype.map useful for?

A

transforming arrays into new arrays based on a callback function

165
Q

What is Array.prototype.reduce useful for?

A

combining an array of values into a single output

166
Q

What is “syntactic sugar”?

A

syntactic restructuring of code to make it easier to write

167
Q

What is the typeof an ES6 class?

A

function

168
Q

Describe ES6 class syntax.

A

class ClassName {}

169
Q

What is “refactoring”?

A

restructuring existing code without changing it’s behavior

170
Q

How are ES Modules different from CommonJS modules?

A

es6 use an import and export keywords vs module.export and require

browsers support es6 modules

171
Q

What kind of modules can Webpack support?

A

CommonJs, ES6, and AMD

172
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A
173
Q
What does this code do?
const wrap = value => () => value;
A
174
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

defined

175
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closure