JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to see data from the past and preserve for the future (store and organize 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, let, or const

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

use equal sign 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, underscore, dollarsigns, and numbers (cannot be first letter)

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

casing matters (N and n matter when calling a variable)

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

gives a variable a text value that is not code

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

can give numerical values that mostly is used for 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

compare values using 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

assigns a value

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

assign a new value using the equal 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

null is assigned, where as undefined is when javascript tell you something is empty

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

gives an identifier for your console log

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

Give five examples of JavaScript primitives.

A

numerical value, string, 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

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

What is string concatenation?

A

appending a string to the end of another string

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 in math and concatention for 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

it is the addition assignment plus whatever string or data type is being added from the original variable

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

What are objects used for?

A

group together data, create subdivisions of data

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

What are object properties?

A

they are sub divisions of objects that store similar data

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

Describe object literal notation.

A

curly braces

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 (name of propert)

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

What are arrays used for?

A

to store items with similar data with an order.

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

Describe array literal notation.

A

square bracket with data values inside

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How are arrays different from "plain" objects?
data is indexed, with a set order
26
What number represents the first index of an array?
0
27
What is the length property of an array
number of values within the array
28
How do you calculate the last index of an array?
.length-1
29
what is a function in Javascript?
function does code repeatable without typing out the code over and over
30
Describe the parts of a function definition
function keyword, name(optional), parameters, curly brace, followed by code and return statement(optional). then closing curly brace
31
Describe the parts of a function call.
the function name followed by parenthesis
32
When comparing them side-by-side, what are the differences between a function call and a function definition?
no function keyword on a function call, no curly braces, and parameters in the function definition versus arguments in function calls
33
What is the difference between a parameter and an argument?
parameter is a placeholder, arguments fills the parameters of the data
34
Why are function parameters useful?
individual data for multiple uses
35
What two effects does a return statement have on the behavior of a function?
spit a value, and stop the the code after it to execute
36
Why do we log things to the console?
verify output and track progress for (debugging)
37
What is a method?
function stored in a object
38
How is a method different from any other function?
methods are attached to objects functions can be called by itself
39
How do you remove the last element from an array?
.pop method
40
How do you round a number down to the nearest integer?
math.floor
41
How do you generate a random number?
math.random method
42
How do you delete an element from an array?
.splice( where to start, how many items to remove)
43
How do you append an element to an array?
.push( ) method
44
How do you break a string up into an array?
.split( )method
45
Do string methods change the original string? How would you check if you weren't sure?
no
46
Is the return value of a function or method useful in every situation?
not all the time
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?
booleans
50
What is the purpose of an if statement?
to check a condition if yes or no do it
51
Is else required in order to use an if statement?
no not necessary
52
Describe the syntax (structure) of an if statement
if keyword , condition and then conditional code block
53
What are the three logical operators?
and, or, not
54
How do you compare two different expressions in the same condition?
logical and logical or
55
What is the purpose of a loop?
keep executing a code until the condition is false
56
What is the purpose of a condition expression in a loop?
it gives it a stop point so that the loop does not run infinite, a break point
57
What does "iteration" mean in the context of loops?
it is 1 execution of a loop, so 4 iterations mean 4 loops
58
When does the condition expression of a while loop get evaluated?
before the code block executes
59
When does the initialization expression of a for loop get evaluated?
it is the very first action (before anything else)
60
When does the condition expression of a for loop get evaluated?
it runs right before each itteration
61
When does the final expression of a for loop get evaluated?
after the code block executes and then it
62
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false
break
63
What does the ++ increment operator do?
adds the value by one
64
How do you iterate through the keys of an object?
for in loop
65
Why do we log things to the console?
check for debugs and make sure code is correct
66
What is a "model"?
create something on a smaller scale to represent the real value
67
Which "document" is being referred to in the phrase Document Object Model?
the HTML document
68
What is the word "object" referring to in the phrase Document Object Model?
javascript object
69
What is a DOM Tree?
Collection of HTML elements similar to a family tree. The element plus all its child element
70
Give two examples of document methods that retrieve a single element from the DOM
getElementByID(), querySelector()
71
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelector(all)
72
Why might you want to assign the return value of a DOM query to a variable?
make storage and will I need it in the future
73
What console method allows you to inspect the properties of a DOM element object?
dir method
74
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
since the page loads top to bottom
75
What does document.querySelector() take as its argument and what does it return?
selectors, argument is string from CSS, it returns an object.
76
What does document.querySelectorAll() take as its argument and what does it return?
it takes everything , and returns NodeLists
77
What is the purpose of events and event handling?
Be able to respond to user interaction
78
Are all possible parameters required to use a JavaScript method or function?
no
79
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEvenListener
80
What is a callback function?
when u have a function passed into another as an argument
81
What object is passed into an event listener callback when the event fires?
event
82
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
object referencing the element
83
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
second one has the function call which will not work
84
What is the className property of element objects?
class attribute's name s for that specific element
85
How do you update the CSS class attribute of an element using JavaScript?
classname property and classlist property
86
What is the textContent property of element objects
It is what is written within the text Content of an element
87
How do you update the text within an element using JavaScript?
element.textContent
88
Is the event parameter of an event listener callback always useful?
Not always as anonymous functions can be used
89
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 as we would not know how many clicks unlesss we console log it.
90
Why is storing information about a program in variables better than only storing it in the DOM?
It gives it a way to organize and see data, otherwise it would be hard to tell
91
What event is fired when a user places their cursor in a form control?
focus
92
What event is fired when a user's cursor leaves a form control?
blurr
93
What event is fired as a user changes the value of a form control?
input
94
What event is fired when a user clicks the "submit" button within a ?
submit
95
What does the event.preventDefault() method do?
prevent default functions of the code
96
What does submitting a form without event.preventDefault() do?
the page will refresh
97
What property of a form element object contains all of the form's controls.
elements
98
What property of a form control object gets and sets its value?
value
99
What is one risk of writing a lot of code without checking to see if it works so far?
code may not be working, and may need to be changed therefore
100
What is an advantage of having your console open when writing a JavaScript program?
101
Does the document.createElement() method insert a new element into the page
not yet, until it appended to the body
102
How do you add an element as a child to another element?
parentElement.appendChild(childElement)
103
What do you pass as the arguments to the element.setAttribute() method?
(name of attribute, value)
104
What steps do you need to take in order to insert a new element into the page?
document.createELement('name of element'), then assign to a variable, then call appenedChild to the parent element they want
105
What is the textContent property of an element object for?
to change
106
Name two ways to set the class attribute of a DOM element.
.className, and setAttribute
107
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)
It can be copied into more than one
108
What is the event.target?
point of interaction, the event area that is happening
109
Why is it possible to listen for events on one element that actually happen its descendent elements?
because of bubbling
110
What DOM element property tells you what type of element it is?
event.target.tagName
111
What does the element.closest() method take as its argument and what does it return?
takes a css selector and it returns the ancestor that is closest to it(parent)
112
How can you remove an element from the DOM?
.remove method
113
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?
Using DOM Delegation
114
What is the event.target?
read only property, element where the even started
115
What is the affect of setting an element to display: none?
Not visible and rendered in the output
116
What does the element.matches() method take as an argument and what does it return?
string name of the class or css selector, it checks if the element matches and returns a boolean
117
How can you retrieve the value of an element's attribute?
getAttribute( string of the name of the attribute)
118
At what steps of the solution would it be helpful to log things to the console?
declaring a variable, going through a value for a loop, changing values. At every step.
119
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?
You would need to add a new event listener and queryselector
120
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?
121
What is JSON?
converting objects and arrays into strings
122
What are serialization and deserialization?
serialization is object and arrays rendered into string deserialization is taking it from a string back into an array and object
123
Why are serialization and deserialization useful?
Its easy to store and read as well as transmit
124
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
125
How do you deserialize a JSON string into a data structure using JavaScript?
json.parse()
126
How to you store data in localStorage?
localStorage.setItem()
127
How to you retrieve data from localStorage?
localStorage.getItem()
128
What data type can localStorage save in the browser?
strings
129
When does the 'beforeunload' event fire on the window object
before the page is refreshed or tab is closed