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
Q

How are arrays different from “plain” objects?

A

data is indexed, with a set order

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

What is the length property of an array

A

number of values within the array

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

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

function does code repeatable without typing out the code over and over

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(optional), parameters, curly brace, followed by code and return statement(optional). then closing curly brace

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

the function name followed by parenthesis

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

no function keyword on a function call, no curly braces, and parameters in the function definition versus arguments in function calls

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

What is the difference between a parameter and an argument?

A

parameter is a placeholder, arguments fills the parameters of the data

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

Why are function parameters useful?

A

individual data for multiple uses

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

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

A

spit a value, and stop the the code after it to execute

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

Why do we log things to the console?

A

verify output and track progress for (debugging)

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

What is a method?

A

function stored in a object

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

How is a method different from any other function?

A

methods are attached to objects functions can be called by itself

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

How do you remove the last element from an array?

A

.pop method

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

How do you generate a random number?

A

math.random method

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

How do you delete an element from an array?

A

.splice( where to start, how many items to remove)

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

How do you append an element to an array?

A

.push( ) method

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

How do you break a string up into an array?

A

.split( )method

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

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

A

no

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

Is the return value of a function or method useful in every situation?

A

not all the time

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

booleans

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

to check a condition if yes or no do it

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

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 keyword , condition and then conditional code block

53
Q

What are the three logical operators?

A

and, or, not

54
Q

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

A

logical and logical or

55
Q

What is the purpose of a loop?

A

keep executing a code until the condition is false

56
Q

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

A

it gives it a stop point so that the loop does not run infinite, a break point

57
Q

What does “iteration” mean in the context of loops?

A

it is 1 execution of a loop, so 4 iterations mean 4 loops

58
Q

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

A

before the code block executes

59
Q

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

A

it is the very first action (before anything else)

60
Q

When does the condition expression of a for loop get evaluated?

A

it runs right before each itteration

61
Q

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

A

after the code block executes and then it

62
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

63
Q

What does the ++ increment operator do?

A

adds the value by one

64
Q

How do you iterate through the keys of an object?

A

for in loop

65
Q

Why do we log things to the console?

A

check for debugs and make sure code is correct

66
Q

What is a “model”?

A

create something on a smaller scale to represent the real value

67
Q

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

A

the HTML document

68
Q

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

A

javascript object

69
Q

What is a DOM Tree?

A

Collection of HTML elements similar to a family tree. The element plus all its child element

70
Q

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

A

getElementByID(), querySelector()

71
Q

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

A

querySelector(all)

72
Q

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

A

make storage and will I need it in the future

73
Q

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

A

dir method

74
Q

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

A

since the page loads top to bottom

75
Q

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

A

selectors, argument is string from CSS, it returns an object.

76
Q

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

A

it takes everything , and returns NodeLists

77
Q

What is the purpose of events and event handling?

A

Be able to respond to user interaction

78
Q

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

A

no

79
Q

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

A

addEvenListener

80
Q

What is a callback function?

A

when u have a function passed into another as an argument

81
Q

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

A

event

82
Q

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

A

object referencing the element

83
Q

What is the difference between these two snippets of code?

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

A

second one has the function call which will not work

84
Q

What is the className property of element objects?

A

class attribute’s name s for that specific element

85
Q

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

A

classname property and classlist property

86
Q

What is the textContent property of element objects

A

It is what is written within the text Content of an element

87
Q

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

A

element.textContent

88
Q

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

A

Not always as anonymous functions can be used

89
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 as we would not know how many clicks unlesss we console log it.

90
Q

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

A

It gives it a way to organize and see data, otherwise it would be hard to tell

91
Q

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

A

focus

92
Q

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

A

blurr

93
Q

What event is fired as a user changes the value of a form control?

A

input

94
Q

What event is fired when a user clicks the “submit” button within a ?

A

submit

95
Q

What does the event.preventDefault() method do?

A

prevent default functions of the code

96
Q

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

A

the page will refresh

97
Q

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

A

elements

98
Q

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

A

value

99
Q

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

A

code may not be working, and may need to be changed therefore

100
Q

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

A
101
Q

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

A

not yet, until it appended to the body

102
Q

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

A

parentElement.appendChild(childElement)

103
Q

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

A

(name of attribute, value)

104
Q

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

A

document.createELement(‘name of element’), then assign to a variable, then call appenedChild to the parent element they want

105
Q

What is the textContent property of an element object for?

A

to change

106
Q

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

A

.className, and setAttribute

107
Q

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

A

It can be copied into more than one

108
Q

What is the event.target?

A

point of interaction, the event area that is happening

109
Q

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

A

because of bubbling

110
Q

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

A

event.target.tagName

111
Q

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

A

takes a css selector and it returns the ancestor that is closest to it(parent)

112
Q

How can you remove an element from the DOM?

A

.remove method

113
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

Using DOM Delegation

114
Q

What is the event.target?

A

read only property, element where the even started

115
Q

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

A

Not visible and rendered in the output

116
Q

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

A

string name of the class or css selector, it checks if the element matches and returns a boolean

117
Q

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

A

getAttribute( string of the name of the attribute)

118
Q

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

A

declaring a variable, going through a value for a loop, changing values. At every step.

119
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

You would need to add a new event listener and queryselector

120
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
121
Q

What is JSON?

A

converting objects and arrays into strings

122
Q

What are serialization and deserialization?

A

serialization is object and arrays rendered into string

deserialization is taking it from a string back into an array and object

123
Q

Why are serialization and deserialization useful?

A

Its easy to store and read as well as transmit

124
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

125
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

json.parse()

126
Q

How to you store data in localStorage?

A

localStorage.setItem()

127
Q

How to you retrieve data from localStorage?

A

localStorage.getItem()

128
Q

What data type can localStorage save in the browser?

A

strings

129
Q

When does the ‘beforeunload’ event fire on the window object

A

before the page is refreshed or tab is closed