JavaScript Flashcards

1
Q

what is the purpose of variables?

A

to store data

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

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

how do you initialize a variable?

A

with the assignment operator

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, _, $. can NOT 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

name must be exact including if a letter is uppercase or lowercase

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

storing and manipulating 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

to perform calculations

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 determine what is run in JS

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

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

reassign using assignment operator

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

undefined is not defined.

null was purposely set to null

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

A

to keep track of what you’re logging.

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

give 5 examples of JavaScript primitives

A

string, number, boolean, undefined, null

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 a string concatenation

A

joining two or more strings.

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

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?

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

adds then assigns 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

to group variables and functions

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

what are object properties?

A

variables within an object

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

describe object literal notation

A

{ key:value, key:value}

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

keyword delete & dot notation or square bracket notation

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

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

what are arrays used for?

A

storing a list of values

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

describe array literal notation

A

[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

the key for each value is an index

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

.length

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

how do you calculate the last index or an array.

A

subtract 1 from the length

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 block of code designed to perform a particular 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

function keyword, function name, parameters, 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

function name, arguments.

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

when comparing side by side what are the differences between a function call and a function definition?

A

call has arguments, definition has parameters and 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 are placeholders within definition, arguments are to pass into a function call.

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

why are function parameters so useful?

A

to use a function multiple times with different arguments.

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

what 2 effects does a return statement have on the behavior of a function?

A

causes a value to be produced from function, ends 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 check if the code is working properly

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 within 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 a function

A

a method is attached to an object

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

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

.splice(start, amount)

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

.unshift, .push, .splice

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

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, strings are immutable. you could check in the console.

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

roughly 40

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 always useful?

A

no

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

roughly 40

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

what 3 letter acronym should you always include in your google search about javascript method and 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

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

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

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

to determine what code runs

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

describe the syntax of an if statement

A

if keyword (condition statement) { code block }

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

what are the 3 logical operators?

A

&&, ||, !

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

how do you compare 2 different expressions in the same condition?

A

&& or ||

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

to repeat behavior

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

what is the purpose of a condition in a loop?

A

to check if the loop keeps going or ends.

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

what does iteration mean in the context of loops?

A

each time the code in the loop runs

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

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

A

before each loop iteration

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

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

A

before everything. only once

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

when does the condition of a for loop get evaluated?

A

before each loop iteration

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

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

A

after the code block runs during each loop iteration.

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

besides a return statement, 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
65
Q

what does the ++ increment operator do?

A

increments by 1

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

what is a ‘model’

A

a copy

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

HTML

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

the node

70
Q

give 2 examples of document methods that retrieve a single element from the DOM

A

document.querySelector, document.getElementByID

71
Q

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

A

document.querySelectorAll

72
Q

why might you want ti assign the return value of a DOM query to a variable

A

to easily access it later

73
Q

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

A

console.dir

74
Q

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

A

the browser needs to parse all elements before the javascript can access them

75
Q

what does document.querySelector take as its argument, and what does it return?

A

takes a selector, returns an HTML element object

76
Q

what does document.querySelectorAll take as its argument, and what does it return?

A

takes a selector, returns a node list

77
Q

what is the purpose of events and event handling?

A

to make the webpage react with user interaction

78
Q

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

A

optional

79
Q

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

A

.addEventListener

80
Q

what is a callback function?

A

a function passed into another function as an argument

81
Q

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

A

event object

82
Q

what is the event target?

A

the element that triggers the event

83
Q

what is the difference between element.addEventListener(‘click’, handleClick)
and element.addEventListener(‘click’, handleClick())

A

parenthesis indicate that the function should run when the page is loaded, and the one without parenthesis runs when the event is fired

84
Q

what is the className property of element objects?

A

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

85
Q

how do you update the css class attribute of an element using javascript?

A

assigning a string value to element.className

86
Q

what is the textContent property of element objects?

A

represents the text content of a node and its descendants

87
Q

how do you update the text within an element using javascript?

A

element.textContent = ‘’

88
Q

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

A

to easily access them later

89
Q

what event Is fired when a user places their cursor in a form control?

A

blur

90
Q

what event is fired when a users cursor leaves a form control?

A

blur

91
Q

what event is fired when a user changes the value of a form control?

A

input

92
Q

what event is fired when a user clicks the submit button within a form

A

submit

93
Q

what does the event.preventDefault method do?

A

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

94
Q

what does submitting a form without event.preventDefault do?

A

prevents the browser from auto reloading the page

95
Q

what property of a form element object contains all of the form controls?

A

elements

96
Q

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

A

value

97
Q

does the document.createElement method insert a new element onto a page?

A

no

98
Q

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

A

.appendChild

99
Q

what do you pass as the arguments to the element.setAttribute method?

A

selector, value

100
Q

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

A

createElement, appendChild

101
Q

what is the textContent property of an element object for?

A

to access or set the text of an element object

102
Q

name two ways to set the class attribute of a DOM element

A

.setAttribute, .className, .classList

103
Q

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

A

to easily create multiple, or add more later easily

104
Q

what is event.target?

A

where the event was fired from

105
Q

why is it possible to listen for events on one element that actually happen on its descendant?

A

bubbling

106
Q

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

A

tagName

107
Q

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

A

takes selector, returns element which is the closest ancestor to the selected element

108
Q

how can you remove an element from the DOM?

A

.remove()

109
Q

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

A

not visible, document flows as if it doesn’t exist

110
Q

what does the element.matches method take as its argument and what does it return?

A

takes selector, returns boolean

111
Q

how can you retrieve the value of an elements attribute?

A

getAttribute method

112
Q

what is JSON?

A

a text based data interchange format used to send and store information in computer systems

113
Q

what are serialization and deserialization

A

serialization is converting a JSON string into an object and deserialization is converting an object into a JSON string

114
Q

why are serialization and deserialization useful?

A

for when you want to transmit data across a network.

115
Q

how do you serialize a data structure into a JSON string using javascript?

A

JSON.stringify

116
Q

how do you deserialize a JSON string into a data structure?

A

JSON.parse

117
Q

how do you store data in localStorage

A

.setItem

118
Q

how do you retrieve data from localStorage?

A

.getItem

119
Q

what datatype can localStorage save in the browser?

A

strings

120
Q

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

A

then the window, document, and its resources are about to be unloaded

121
Q

what is a method?

A

a function within an object

122
Q

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

A

definition has code block. call does not

123
Q

describe method definition syntax

A

methodName(parameters) {code block}

124
Q

describe method call syntax

A

methodName(arguments);

125
Q

how is a method different from any other function?

A

a method is attached to an object

126
Q

what is the defining characteristic of Object Oriented Programming?

A

it can contain both data and behavior

127
Q

what are the four principals of Object Oriented Programming?

A

abstraction, encapsulation, inheritance, polymorphism

128
Q

what is ‘abstraction’?

A

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

129
Q

what does API stand for?

A

Application Programming Interface

130
Q

what is the purpose of an API?

A

it simplifies programming by abstracting the underlying implementation and only exposing object or actions the developer needs.

131
Q

what is this in JavaScript?

A

an implicit parameter of all JavaScript functions

132
Q

what does it mean to say that this is an ‘implicit’ parameter?

A

available in a function code block even though it wasn’t in parameter or declared with var

133
Q

when is the value of this determined in a function?

A

at call time

134
Q

what kind of inheritance does the JavaScript programming language do?

A

an object that contains properties and 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 methods?

A

methods are defined on a prototype object & they borrow those methods when needed.

136
Q

if an object does not have its own property or methods by a given key, where does JavaScript look for it?

A

the __proto__ property

137
Q

what does the new operator do?

A

creates a blank JavaScript object, adds __proto__, binds created object to this.

138
Q

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

A

__proto__

139
Q

what does the instanceof operator do?

A

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

140
Q

what is a ‘callback’ function

A

a function passed into another function as an argument

141
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

142
Q

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

A

setInterval

143
Q

what is the default time delay if you omit the delay parameter from setTimeout or setInterval?

A

0

144
Q

what do setTimeout and setInterval return?

A

timeout id, and interval id. (number)

145
Q

what is a client?

A

service requester

146
Q

what is a server?

A

provider of resource or service

147
Q

which HTTP method does a browser issue to a web server when you visit a URL?

A

GET

148
Q

what 3 things are on the start-line of an HTTP request method?

A

an HTTP method, the request target, the HTTP version

149
Q

what 3 things are on the start line of an HTTP response?

A

protocol version, status code, status text

150
Q

what are HTTP headers?

A

they let the client and server pass additional information with an HTTP request or response

151
Q

where would you go if you wanted to learn more about a specific HTTP header?

A

MDN

152
Q

is a body required for a valid HTTP request or response message?

A

no

153
Q

what is AJAX?

A

it allows you to request data from a server and load it without having to refresh the entire page

154
Q

what does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

155
Q

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

A

XMLHttpRequest

156
Q

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

A

load

157
Q

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

A

a chunk of code grouped together within curly braces. function code block, if code block, loop code block

158
Q

what does block scope mean?

A

exists only within that block

159
Q

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

A

block scope

160
Q

what is the difference between const and let

A

const variables can not be reassigned

161
Q

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

A

the value of the variable can be manipulated, just not directly reassigned

162
Q

how should you decide which declaration to use?

A

if you are not reassigning the value use const, if you are use let

163
Q

what is the syntax for writing a template literal?

A

` ${ }`

164
Q

what is ‘string interpolation’

A

in javascript, when js automatically replaces expressions with their values in template literals

165
Q

what is the syntax for Object Destructuring?

A

const { property: varName} = origVarName

166
Q

what is the syntax for Array Destructuring?

A

const [varName1, varName2] = origVarName

167
Q

how can you tell the difference between Destructuring and creating Object/Array literals?

A

{ } or [] on left side for destructuring

168
Q

what is the syntax for defining an arrow function?

A

const VarName = (parameters) => { code}

169
Q

when an arrow functions body is left out what changes in its functionality?

A

can only have one expression, no statements or loops

170
Q

how is the value of this determined with an arrow function?

A

it is determined within the function code block