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
Describe array literal notation.
[values, values ];
26
How are arrays different from "plain" objects?
arrays are numeric will repair themselves if something is deleted
27
What number represents the first index of an array?
0
28
How do you calculate the last index of an array?
subtract by 1
29
What is a function in JavaScript?
series of statements that is repeatable
30
Describe the parts of a function definition.
function keyword name of function parameter list return statement function
31
Describe the parts of a function call.
name of the function and arguments if it requires it
32
What is the difference between a parameter and an argument?
parameter is the name for data that will be used later | arguments is data the
33
What two effects does a return statement have on the behavior of a function?
allows to return result
34
Why do we log things to the console?
to debug
35
What is a method?
function being stored in a property
36
How is a method different from any other function?
methods have to say where they're coming from
37
How do you remove the last element from an array?
pop
38
How do you round a number down to the nearest integer?
floor
39
How do you generate a random number?
random
40
How do you delete an element from an array?
splice
41
How do you append an element to an array?
push
42
How do you break a string up into an array?
split
43
Do string methods change the original string? How would you check if you weren't sure?
No check the return value on mdn
44
Roughly how many string methods are there according to the MDN Web docs?
alot
45
Is the return value of a function or method useful in every situation?
no
46
Roughly how many array methods are there according to the MDN Web docs?
30
47
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
48
Give 6 examples of comparison operators.
,=>,<=,||
49
What data type do comparison expressions evaluate to?
true or false
50
What is the purpose of an if statement?
making decisions
51
Is else required in order to use an if statement?
no
52
Describe the syntax (structure) of an if statement.
if condition(parameter){}
53
What are the three logical operators?
logical (and or not)
54
How do you compare two different expressions in the same condition?
using logical and, or
55
comparison
to repeat over and over again
56
What data type do comparison expressions evaluate to?
to continue or stop
57
What is the purpose of a loop?
everytime the code block runs
58
What is the purpose of a condition expression in a loop?
at the beginning of the loop
59
What does "iteration" mean in the context of loops?
in the beginning
60
When does the condition expression of a while loop get evaluated?
before the code block
61
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
62
What does the ++ increment operator do?
increments variable by 1
63
How do you iterate through the keys of an object?
for in
64
Why do we log things to the console?
to debug
65
What is a "model"?
representation of the original
66
Which "document" is being referred to in the phrase Document Object Model?
html
67
What is the word "object" referring to in the phrase Document Object Model?
referring to javascript objects
68
Give two examples of document methods that retrieve a single element from the DOM.
``` getElementByID queryselector() ```
69
Give one example of a document method that retrieves multiple elements from the DOM at once.
queryseleectorall
70
Why might you want to assign the return value of a DOM query to a variable?
to use it later
71
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick( ))
2nd line of code gives an undefined result and has a callback function that we dont call the browser does
72
What does document.querySelector() take as its argument and what does it return?
Returns the first Element within the document that matches the specified selector, or group of selectors
73
What does document.querySelectorAll() take as its argument and what does it return?
takes in node list and return everything
74
Why do we log things to the console?
to debug
75
What is the purpose of events and event handling?
to verify user inputs
76
Are all possible parameters required to use a JavaScript method or function?
no
77
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListner method
78
What is a callback function?
a function being passed as a value
79
What object is passed into an event listener callback when the event fires?
target
80
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
a reference to the object where the event occurred
81
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick( ))
theres no callback function of the 2nd line of code
82
What is the className property of element objects?
get value of class /??????????
83
How do you update the CSS class attribute of an element using JavaScript?
????????
84
What is the textContent property of element objects?
represent the text inside the element
85
How do you update the text within an element using JavaScript?
get element from dom
86
Is the event parameter of an event listener callback always useful?
no but prepare for it
87
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
more complicated
88
Why is storing information about a program in variables better than only storing it in the DOM?
???????
89
What event is fired when a user places their cursor in a form control?
focus
90
What event is fired when a user's cursor leaves a form control?
blur
91
What event is fired as a user changes the value of a form control?
input
92
What event is fired when a user clicks the "submit" button within a ?
submit
93
What does the event.preventDefault() method do?
prevents default action
94
What does submitting a form without event.preventDefault() do?
????????
95
What property of a form element object contains all of the form's controls.
elements
96
What property of form a control object gets and sets its value?
value property
97
What is one risk of writing a lot of code without checking to see if it works so far?
it can be broken and will be difficult to find those mistakes
98
What is an advantage of having your console open when writing a JavaScript program?
you can see where the code went wrong
99
Does the document.createElement() method insert a new element into the page?
its doesnt
100
How do you add an element as a child to another element?
append child
101
What do you pass as the arguments to the element.setAttribute() method?
name of attribute new value for attribute
102
What steps do you need to take in order to insert a new element into the page?
????????
103
What is the textContent property of an element object for?
contains the text with that element
104
Name two ways to set the class attribute of a DOM element.
class name, set attribute ,class list
105
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
??????
106
What is the event.target?
stores event where it originated from
107
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling
108
What DOM element property tells you what type of element it is?
tagname
109
What does the element.closest() method take as its argument and what does it return?
selector returns up the dom tree which is closest to its ancestor
110
How can you remove an element from the DOM?
remove ()
111
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?
add event listener to that parent
112
What is the event.target?
a reference to the object onto which the event was dispatched
113
What is the affect of setting an element to display: none?
affected element will disappear.
114
What does the element.matches() method take as an argument and what does it return?
selectorString and returns a boolean (if element matchrs css selector)
115
How can you retrieve the value of an element's attribute?
getAttribute
116
At what steps of the solution would it be helpful to log things to the console?
all the time? query dom
117
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?
????????
118
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?
??????
119
What is a method?
a function stored in a property
120
How can you tell the difference between a method definition and a method call?
definition "property:function()" | call "property.method()"
121
Describe method definition syntax (structure).
definition "property:function()"
122
Describe method call syntax (structure).
call "property.method()"
123
How is a method different from any other function?
method are functions attached to objects
124
What is the defining characteristic of Object-Oriented Programming?
keep them together
125
What are the four "principles" of Object-Oriented Programming?
Encapsulation, Abstraction, Inheritance, and Polymorphism.
126
What is "abstraction"?
taking something complex and simplifying it
127
What does API stand for?
Application programming interface
128
What is the purpose of an API?
delivers a user response to a system and sends the system's response back to a user.
129
What is this in JavaScript?
where the object code is run
130
What does it mean to say that this is an "implicit parameter"?
???????
131
When is the value of this determined in a function; call time or definition time?
?????
132
How can you tell what the value of this will be for a particular function or method definition?
you cant
133
How can you tell what the value of this is for a particular function or method call?
left of the dot
134
What kind of inheritance does the JavaScript programming language use?
prototype based inheritance
135
What is a prototype in JavaScript?
???????????
136
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?
prototypal inheritance
137
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
_proto_
138
What does the new operator do?
create an instance of a user-defined object type or of one of the built-in object types that has a constructor function
139
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
140
What does the instanceof operator do?
returns true or false if object on the left matches the right
141
What is a "callback" function?
a function passed into another function as an argument
142
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
143
How can you set up a function to be called repeatedly without using a loop?
setInterval
144
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 default time
145
What do setTimeout() and setInterval() return?
intervalID and its an integer
146
What is AJAX?
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
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML.
148
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
149
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load event
150
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
its still an event and they're both branch off of a prototype