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

var

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

=

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

they are specific to how they are typed

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

store and manipulate text

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

What is the purpose of a number?

A

to show value that would be number quantity

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 if something is true or false

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

putting in a value to something

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

just change the 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 an empty value, undefined means the variable has been declared but not defined

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

point of reference

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 numbers null undefined values

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

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

combination of 2 or more string values

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

to add values or concatenate strings

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

What data type is returned by comparing two values (, ===, etc)?

A

boolean

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

What does the += “plus-equals” operator do?

A

adds the value of the right operand to a variable and assigns the result 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 group variables or functions

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

What are object properties?

A

variables inside objects

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

Describe object literal notation.

A

{properties: 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

delete

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

to be put in a list

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

Describe array literal notation.

A

[values, 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 are numeric will repair themselves if something is deleted

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

How do you calculate the last index of an array?

A

subtract by 1

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

What is a function in JavaScript?

A

series of statements that is repeatable

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

Describe the parts of a function definition.

A

function keyword name of function parameter list return statement function

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

Describe the parts of a function call.

A

name of the function and arguments if it requires it

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

What is the difference between a parameter and an argument?

A

parameter is the name for data that will be used later

arguments is data the

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

What two effects does a return statement have on the behavior of a function?

A

allows to return result

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

Why do we log things to the console?

A

to debug

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

What is a method?

A

function being stored in a property

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

How is a method different from any other function?

A

methods have to say where they’re coming from

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

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

A

floor

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

How do you generate a random number?

A

random

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

How do you delete an element from an array?

A

splice

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

How do you append an element to an array?

A

push

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

How do you break a string up into an array?

A

split

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

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

A

No check the return value on mdn

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

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

A

alot

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

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

A

30

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

Give 6 examples of comparison operators.

A

,=>,<=,||

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

What data type do comparison expressions evaluate to?

A

true or false

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

What is the purpose of an if statement?

A

making decisions

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

Describe the syntax (structure) of an if statement.

A

if condition(parameter){}

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

What are the three logical operators?

A

logical (and or not)

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

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

A

using logical and, or

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

comparison

A

to repeat over and over again

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

What data type do comparison expressions evaluate to?

A

to continue or stop

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

everytime the code block runs

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

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

A

at the beginning of the loop

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

in the beginning

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

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

62
Q

What does the ++ increment operator do?

A

increments variable by 1

63
Q

How do you iterate through the keys of an object?

A

for in

64
Q

Why do we log things to the console?

A

to debug

65
Q

What is a “model”?

A

representation of the original

66
Q

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

A

html

67
Q

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

A

referring to javascript objects

68
Q

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

A
getElementByID
queryselector()
69
Q

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

A

queryseleectorall

70
Q

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

A

to use it later

71
Q

What is the difference between these two snippets of code?

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

A

2nd line of code gives an undefined result and has a callback function that we dont call the browser does

72
Q

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

A

Returns the first Element within the document that matches the specified selector, or group of selectors

73
Q

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

A

takes in node list and return everything

74
Q

Why do we log things to the console?

A

to debug

75
Q

What is the purpose of events and event handling?

A

to verify user inputs

76
Q

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

A

no

77
Q

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

A

addEventListner method

78
Q

What is a callback function?

A

a function being passed as a value

79
Q

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

A

target

80
Q

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

A

a reference to the object where the event occurred

81
Q

What is the difference between these two snippets of code?

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

A

theres no callback function of the 2nd line of code

82
Q

What is the className property of element objects?

A

get value of class /??????????

83
Q

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

A

????????

84
Q

What is the textContent property of element objects?

A

represent the text inside the element

85
Q

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

A

get element from dom

86
Q

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

A

no but prepare for it

87
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

more complicated

88
Q

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

A

???????

89
Q

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

A

focus

90
Q

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

A

blur

91
Q

What event is fired as 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 ?

A

submit

93
Q

What does the event.preventDefault() method do?

A

prevents default action

94
Q

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

A

????????

95
Q

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

A

elements

96
Q

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

A

value property

97
Q

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

A

it can be broken and will be difficult to find those mistakes

98
Q

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

A

you can see where the code went wrong

99
Q

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

A

its doesnt

100
Q

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

A

append child

101
Q

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

A

name of attribute new value for attribute

102
Q

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

A

????????

103
Q

What is the textContent property of an element object for?

A

contains the text with that element

104
Q

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

A

class name, set attribute ,class list

105
Q

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

A

??????

106
Q

What is the event.target?

A

stores event where it originated from

107
Q

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

A

event bubbling

108
Q

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

A

tagname

109
Q

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

A

selector returns up the dom tree which is closest to its ancestor

110
Q

How can you remove an element from the DOM?

A

remove ()

111
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 that parent

112
Q

What is the event.target?

A

a reference to the object onto which the event was dispatched

113
Q

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

A

affected element will disappear.

114
Q

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

A

selectorString and returns a boolean (if element matchrs css selector)

115
Q

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

A

getAttribute

116
Q

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

A

all the time? query dom

117
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

????????

118
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

??????

119
Q

What is a method?

A

a function stored in a property

120
Q

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

A

definition “property:function()”

call “property.method()”

121
Q

Describe method definition syntax (structure).

A

definition “property:function()”

122
Q

Describe method call syntax (structure).

A

call “property.method()”

123
Q

How is a method different from any other function?

A

method are functions attached to objects

124
Q

What is the defining characteristic of Object-Oriented Programming?

A

keep them together

125
Q

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

A

Encapsulation, Abstraction, Inheritance, and Polymorphism.

126
Q

What is “abstraction”?

A

taking something complex and simplifying it

127
Q

What does API stand for?

A

Application programming interface

128
Q

What is the purpose of an API?

A

delivers a user response to a system and sends the system’s response back to a user.

129
Q

What is this in JavaScript?

A

where the object code is run

130
Q

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

A

???????

131
Q

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

A

?????

132
Q

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

A

you cant

133
Q

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

A

left of the dot

134
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype based inheritance

135
Q

What is a prototype in JavaScript?

A

???????????

136
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

prototypal inheritance

137
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

138
Q

What does the new operator do?

A

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

139
Q

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

A

prototype property

140
Q

What does the instanceof operator do?

A

returns true or false if object on the left matches the right

141
Q

What is a “callback” function?

A

a function passed into another function as an argument

142
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

143
Q

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

A

setInterval

144
Q

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

A

0 default time

145
Q

What do setTimeout() and setInterval() return?

A

intervalID and its an integer

146
Q

What is AJAX?

A

Read data from a web server - after a web page has loaded
Update a web page without reloading the page
Send data to a web server - in the background

147
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML.

148
Q

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

A

XMLHttpRequest

149
Q

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

A

load event

150
Q

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

A

its still an event and they’re both branch off of a prototype