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
describe array literal notation
[value, value]
26
how are arrays different from 'plain' objects?
the key for each value is an index
27
what number represents the first index of an array?
0
28
what is the length property of an array?
.length
29
how do you calculate the last index or an array.
subtract 1 from the length
30
what is a function in javascript?
a block of code designed to perform a particular task.
31
describe the parts of a function definition
function keyword, function name, parameters, code block.
32
describe the parts of a function call
function name, arguments.
33
when comparing side by side what are the differences between a function call and a function definition?
call has arguments, definition has parameters and code block.
34
what is the difference between a parameter and an argument
parameters are placeholders within definition, arguments are to pass into a function call.
35
why are function parameters so useful?
to use a function multiple times with different arguments.
36
what 2 effects does a return statement have on the behavior of a function?
causes a value to be produced from function, ends the function
37
why do we log things to the console?
to check if the code is working properly
38
what is a method?
a function stored within an object
39
how is a method different from a function
a method is attached to an object
40
how do you remove the last element from an array?
.pop()
41
how do you round a number down to the nearest integer?
Math.floor()
42
how do you generate a random number?
Math.random()
43
how do you delete an element from an array?
.splice(start, amount)
44
how do you append an element to an array?
.unshift, .push, .splice
45
how do you break a string up into an array?
.split(onCharacter)
46
do string methods change the original string? how would you check if you weren't sure?
No, strings are immutable. you could check in the console.
47
roughly how many string methods are there according to the MDN Web docs?
roughly 40
48
is the return value of a function or method always useful?
no
49
roughly how many array methods are there according to the MDN Web docs?
roughly 40
50
what 3 letter acronym should you always include in your google search about javascript method and css property?
MDN
51
give 6 examples of comparison operators
, ===, !==, >=, <=
52
what data type do comparison expressions evaluate to?
boolean
53
what is the purpose of an if statement?
to determine what code runs
54
describe the syntax of an if statement
if keyword (condition statement) { code block }
55
what are the 3 logical operators?
&&, ||, !
56
how do you compare 2 different expressions in the same condition?
&& or ||
57
what is the purpose of a loop?
to repeat behavior
58
what is the purpose of a condition in a loop?
to check if the loop keeps going or ends.
59
what does iteration mean in the context of loops?
each time the code in the loop runs
60
when does the condition expression of a while loop get evaluated?
before each loop iteration
61
when does the initialization expression of a for loop get evaluated?
before everything. only once
62
when does the condition of a for loop get evaluated?
before each loop iteration
63
when does the final expression of a for loop get evaluated?
after the code block runs during each loop iteration.
64
besides a return statement, which keyword exits a loop before its condition expression evaluates to false?
break
65
what does the ++ increment operator do?
increments by 1
66
how do you iterate through the keys of an object?
for...in loop
67
what is a 'model'
a copy
68
which 'document' is being referred to in the phrase Document Object Model
HTML
69
what is the word 'object' referring to in the phrase Document Object Model
the node
70
give 2 examples of document methods that retrieve a single element from the DOM
document.querySelector, document.getElementByID
71
give one example of a document method that retrieves multiple elements from the DOM at once
document.querySelectorAll
72
why might you want ti assign the return value of a DOM query to a variable
to easily access it later
73
what console method allows you to inspect the properties of a DOM element object
console.dir
74
why would a script tag need to be placed at the bottom of the HTML content instead of the top?
the browser needs to parse all elements before the javascript can access them
75
what does document.querySelector take as its argument, and what does it return?
takes a selector, returns an HTML element object
76
what does document.querySelectorAll take as its argument, and what does it return?
takes a selector, returns a node list
77
what is the purpose of events and event handling?
to make the webpage react with user interaction
78
what do [] square brackets mean in function and method syntax documentation?
optional
79
what method of element objects lets you set up a function to be called when a specific type of event occurs
.addEventListener
80
what is a callback function?
a function passed into another function as an argument
81
what object is passed into an event listener callback when the event fires?
event object
82
what is the event target?
the element that triggers the event
83
what is the difference between element.addEventListener('click', handleClick) and element.addEventListener('click', handleClick())
parenthesis indicate that the function should run when the page is loaded, and the one without parenthesis runs when the event is fired
84
what is the className property of element objects?
gets and sets the value of the class attribute of a specified element
85
how do you update the css class attribute of an element using javascript?
assigning a string value to element.className
86
what is the textContent property of element objects?
represents the text content of a node and its descendants
87
how do you update the text within an element using javascript?
element.textContent = ''
88
why is storing information about a program in variables better than only storing in the DOM?
to easily access them later
89
what event Is fired when a user places their cursor in a form control?
blur
90
what event is fired when a users cursor leaves a form control?
blur
91
what event is fired when a user changes the value of a form control?
input
92
what event is fired when a user clicks the submit button within a form
submit
93
what does the event.preventDefault method do?
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
what does submitting a form without event.preventDefault do?
prevents the browser from auto reloading the page
95
what property of a form element object contains all of the form controls?
elements
96
what property of a form control object gets and sets its value?
value
97
does the document.createElement method insert a new element onto a page?
no
98
how do you add an element as a child to another element?
.appendChild
99
what do you pass as the arguments to the element.setAttribute method?
selector, value
100
what steps do you need to take in order to insert a new element into the page?
createElement, appendChild
101
what is the textContent property of an element object for?
to access or set the text of an element object
102
name two ways to set the class attribute of a DOM element
.setAttribute, .className, .classList
103
what are two advantages of defining a function to create something (like the work of creating a DOM tree)
to easily create multiple, or add more later easily
104
what is event.target?
where the event was fired from
105
why is it possible to listen for events on one element that actually happen on its descendant?
bubbling
106
what DOM element property tells you what type of element it is?
tagName
107
what does the element.closest method take as its argument and what does it return?
takes selector, returns element which is the closest ancestor to the selected element
108
how can you remove an element from the DOM?
.remove()
109
what is the affect of setting an element to display:none?
not visible, document flows as if it doesn't exist
110
what does the element.matches method take as its argument and what does it return?
takes selector, returns boolean
111
how can you retrieve the value of an elements attribute?
getAttribute method
112
what is JSON?
a text based data interchange format used to send and store information in computer systems
113
what are serialization and deserialization
serialization is converting a JSON string into an object and deserialization is converting an object into a JSON string
114
why are serialization and deserialization useful?
for when you want to transmit data across a network.
115
how do you serialize a data structure into a JSON string using javascript?
JSON.stringify
116
how do you deserialize a JSON string into a data structure?
JSON.parse
117
how do you store data in localStorage
.setItem
118
how do you retrieve data from localStorage?
.getItem
119
what datatype can localStorage save in the browser?
strings
120
when does the 'beforeunload' event fire on the window object?
then the window, document, and its resources are about to be unloaded
121
what is a method?
a function within an object
122
how can you tell the difference between a method definition and a method call?
definition has code block. call does not
123
describe method definition syntax
methodName(parameters) {code block}
124
describe method call syntax
methodName(arguments);
125
how is a method different from any other function?
a method is attached to an object
126
what is the defining characteristic of Object Oriented Programming?
it can contain both data and behavior
127
what are the four principals of Object Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
128
what is 'abstraction'?
being able to work with (possibly) complex things in simple ways
129
what does API stand for?
Application Programming Interface
130
what is the purpose of an API?
it simplifies programming by abstracting the underlying implementation and only exposing object or actions the developer needs.
131
what is this in JavaScript?
an implicit parameter of all JavaScript functions
132
what does it mean to say that this is an 'implicit' parameter?
available in a function code block even though it wasn't in parameter or declared with var
133
when is the value of this determined in a function?
at call time
134
what kind of inheritance does the JavaScript programming language do?
an object that contains properties and methods that can be used by other objects
135
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?
methods are defined on a prototype object & they borrow those methods when needed.
136
if an object does not have its own property or methods by a given key, where does JavaScript look for it?
the __proto__ property
137
what does the new operator do?
creates a blank JavaScript object, adds __proto__, binds created object to this.
138
what property of JavaScript functions can store shared behavior for instances created with new?
__proto__
139
what does the instanceof operator do?
tests to see if the prototype property of a constructor function appears anywhere in the prototype chain of an object
140
what is a 'callback' function
a function passed into another function as an argument
141
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?
setTimeout
142
how can you set up a function to be called repeatedly without a loop?
setInterval
143
what is the default time delay if you omit the delay parameter from setTimeout or setInterval?
0
144
what do setTimeout and setInterval return?
timeout id, and interval id. (number)
145
what is a client?
service requester
146
what is a server?
provider of resource or service
147
which HTTP method does a browser issue to a web server when you visit a URL?
GET
148
what 3 things are on the start-line of an HTTP request method?
an HTTP method, the request target, the HTTP version
149
what 3 things are on the start line of an HTTP response?
protocol version, status code, status text
150
what are HTTP headers?
they let the client and server pass additional information with an HTTP request or response
151
where would you go if you wanted to learn more about a specific HTTP header?
MDN
152
is a body required for a valid HTTP request or response message?
no
153
what is AJAX?
it allows you to request data from a server and load it without having to refresh the entire page
154
what does the AJAX acronym stand for?
Asynchronous JavaScript and XML
155
which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
156
what event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
157
what is a code block? what are some examples of a code block?
a chunk of code grouped together within curly braces. function code block, if code block, loop code block
158
what does block scope mean?
exists only within that block
159
what is the scope of a variable declared with const or let?
block scope
160
what is the difference between const and let
const variables can not be reassigned
161
why is it possible to .push() a new value into a const variable that points to an array?
the value of the variable can be manipulated, just not directly reassigned
162
how should you decide which declaration to use?
if you are not reassigning the value use const, if you are use let
163
what is the syntax for writing a template literal?
` ${ }`
164
what is 'string interpolation'
in javascript, when js automatically replaces expressions with their values in template literals
165
what is the syntax for Object Destructuring?
const { property: varName} = origVarName
166
what is the syntax for Array Destructuring?
const [varName1, varName2] = origVarName
167
how can you tell the difference between Destructuring and creating Object/Array literals?
{ } or [] on left side for destructuring
168
what is the syntax for defining an arrow function?
const VarName = (parameters) => { code}
169
when an arrow functions body is left out what changes in its functionality?
can only have one expression, no statements or loops
170
how is the value of this determined with an arrow function?
it is determined within the function code block