Javascript Flashcards

1
Q

What is the purpose of variables?

A

It allows you to store data

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

How do youdeclarea variable?

A

var keyword with the variable name

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

Can start with $, _, or any letter
Cannot start with a number
Cannot use - or .
Cannot use keywords like var

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

happy and hAppy will be two different variables

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

To provide data as 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 provide numeric value for a variable or for 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

Give a true or false value

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

you can assign the variable to a new value

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

What is the difference betweennullandundefined?

A

Null is intentionally left empty, Undefined is a variable with no value
var apple;
VS.
var apple = undefined;

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

It allows you to see if you code is working properly and provides clarity

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

Give five examples of JavaScript primitives.

A

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

Joining of strings using + operator

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 or concatenation
Adds one value to anoter

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 adds the value on the right side of the operator to the value of the variable on the left side and reassigns it to the variable on the left side

Var motto = fullName + ‘ is the GOAT’
Motto += ‘ is the GOAT’

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

What are objects used for?

A

Storing multiple functions or properties of an item

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

What are object properties?

A

key value pairs relating to the defined variable

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

Describe object literal notation.

A

A variable is defined
There is the opening curling brace for the code block
Properties made of key value pairs separated by commas
closing curly brace of the code block
Semicolon

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 variable.property

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

Reassign the value of the variable
Create a var.property and have a value assigned to it

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

What are arrays used for?

A

It stores a list of values that are related to each other

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

Describe array literal notation

A

Var is defined
opening brace for the code block
string, numbers, or booleans separated by commas
closing brace for the code block
semicolon

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

Instead of properties with their own unique key value pairs, the key for each value in an array is represented by its index number

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

What is thelengthproperty of an array?

A

The number of items in the array

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

How do you calculate the last index of an array?

A

Array[Array.length - 1]

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

What are objects used for?

A

Storing multiple functions or attributes of an item

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

What are object properties?

A

Key value pairs

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

Describe object literal notation.

A

A variable being defined
Start of the code block
Properties made of key value pairs separated by commas
Closing of the code block
Semicolon

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

How do you remove a property from an object?

A

Delete obj.property

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

What are the two ways to get or update the value of a property?

A

Dot notation and bracket notation

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

What is a function in JavaScript?

A

A block of code that executes a task and can easily be called on

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

Describe the parts of a functiondefinition.

A

Function keyword, an optional name for the function, 0 or more parameters separated by commas enclosed by parentheses, opening curly brace for the code block
Optional return statement
End of the code block

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

Describe the parts of a functioncall.

A

The functions name, 0 or more arguments separated by commas enclosed in parentheses

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

When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?

A

There is no function keyword in the call
The parameter is a representation of the actual argument
There is no code block in a function call

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

What is the difference between aparameterand anargument?

A

A parameter is part of a function definition and an argument is part of the function call

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

Why are functionparametersuseful?

A

It acts as a placeholder until you have the actual values when the function is called

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

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

A

It produces a value from the function
It ends the function code block from running anything else

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

Why do we log things to the console?

A

Using the log method of the console object console.log();

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

What is a method?

A

A function inside of an object

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

How is a method different from any other function?

A

It is part of an object while other functions are not

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

How do you remove the last element from an array?

A

Pop method (shift method to remove first element)

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

How do you generate a random number?

A

Math.random() The random method of the Math object

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

How do you delete an element from an array?

A

Splice method (first number is which index to before which index to start at, second number is how many elements to remove)

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

How do you append an element to an array?

A

Push method to add to end of array. Unshift method to add to beginning of array

51
Q

How do you break a string up into an array?

A

Split method

52
Q

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

A

No they can only split or concatenate the string or capitalize it.
You can log it to the console to check

53
Q

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

A

About 50

54
Q

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

A

No because some methods may give a random value

55
Q

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

A

About 40

56
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

57
Q

Give 6 examples of comparison operators.

A

> , >=, <, <=, !==, ===

58
Q

What data type do comparison expressions evaluate to?

A

Boolean

59
Q

What is the purpose of anifstatement?

A

To run different blocks of code based on if that block of code meets a condition

60
Q

Iselserequired in order to use anifstatement?

A

No, if you only need the code to run if the condition is true

61
Q

Describe the syntax (structure) of anifstatement.

A

If keyword, parentheses with the condition inside, curly brace for the code block, code in the code block to execute followed by semi colon, closing curly brace

62
Q

What are the three logical operators?

A

&& logical and, || logical or, ! Logical not

63
Q

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

A

By using a logical operator in between them

64
Q

What is the purpose of a loop?

A

It checks a condition until it returns false

65
Q

What is the purpose of aconditionexpression in a loop?

A

It checks to see if the code should run again or to stop

66
Q

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

A

It is each time the loop runs

67
Q

Whendoes theconditionexpression of awhileloop get evaluated?

A

The beginning of each loop until the condition is not met

68
Q

Whendoes theinitializationexpression of aforloop get evaluated?

A

It is evaluated before the code block runs for the first time

69
Q

Whendoes theconditionexpression of aforloop get evaluated?

A

It is evaluated at the beginning of each loop iteration

70
Q

Whendoes thefinalexpression of aforloop get evaluated?

A

it is evaluated at the end of each loop iteration

71
Q

Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?

A

Keyword break

72
Q

What does the++increment operator do?

A

It adds one to the counter every time the loop runs and drives the loop until it no longer runs

73
Q

How do you iterate through the keys of an object?

A

using for in loop

74
Q

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

A

Focus Event

75
Q

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

A

Blur event

76
Q

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

A

input event

77
Q

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

A

Submit event

78
Q

What does theevent.preventDefault()method do?

A

It prevents the browser from following through the the events normal actions

79
Q

What does submitting a form withoutevent.preventDefault()do?

A

It will reload the page

80
Q

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

A

Elements property

81
Q

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

A

Value property

82
Q

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

A

you will have to backtrack to find your mistake

83
Q

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

A

You can check if everything is working properly and debug as you go

84
Q

What are objects used for?

A

Storing multiple methods or properties of an item

85
Q

What are object properties?

A

Key value pairs that are attributes of that object

86
Q

Describe object literal notation.

A

Object name stored as variable
Opening curly brace for start of the code block
Properties made of key value pairs
Closing curly brace for code block
Semicolon

87
Q

How do you remove a property from an object?

A

delete object.property

88
Q

What are the two ways to get or update the value of a property?

A

dot notation and bracket notation

89
Q

Why do we log things to the console?

A

check our work and to debug

90
Q

What is a method?

A

a function inside of an object

91
Q

How is a method different from any other function?

A

It is part of an object while other functions are not

92
Q

How do you remove the last element from an array?

A

pop method

93
Q

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

A

Math.floor()

94
Q

How do you generate a random number?

A

splice()

95
Q

How do you append an element to an array?

A

push()

96
Q

How do you break a string up into an array?

A

split()

97
Q

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

A

No they can only split or concatenate the string or capitalize it.
You can log it to the console to check

98
Q

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

A

About 50

99
Q

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

A

no because some methods may give a random value?

100
Q

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

A

About 40

101
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

102
Q

Give 6 examples of comparison operators.

A

> , >=, <, <=, !==, ===

103
Q

What data type do comparison expressions evaluate to?

A

Boolean

104
Q

What is the purpose of anifstatement?

A

To run different blocks of code based on if that block of code meets a condition

105
Q

Iselserequired in order to use anifstatement?

A

No, if statement will always be true

106
Q

Describe the syntax (structure) of anifstatement.

A

If keyword, parentheses with the condition inside, curly brace for the code block, code in the code block to execute followed by semi colon, closing curly brace

107
Q

What are the three logical operators?

A

&& logical and, || logical or, ! logical not

108
Q

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

A

By using a logical operator in between them

109
Q

What is theevent.target?

A

It is the element that the target was triggered from

110
Q

What is the affect of setting an element todisplay: none?

A

The element will disappear from the webpage

111
Q

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

A

It takes a css selector, as a string, for the argument and it returns true if the element matches the selector and false if not

112
Q

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

A

getAttribute method

113
Q

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

A

Logging e.target to make sure it is only firing when it is supposed to
Logging the nodelists to visualize what we were looping through
Checking to see if the tabs were changing classes properly when being clicked
When checking to see if the attribute values were matching each other

114
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

We would need to make a separate event listener for the new tab and view divs.

115
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

We would have to write a long list of if else statements and check conditions for each index of the nodelists

116
Q

What is JSON?

A

Text format for representing javascript object syntax

117
Q

What are serialization and deserialization?

A

Converting an object into bytes that can be saved or transferred over a network
Deserialization is taking the bytes and converting it back to the object

118
Q

Why are serialization and deserialization useful?

A

Provides a useful method to transport data from one place to another

119
Q

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

A

The JSON.stringify() method

120
Q

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

A

The JSON.parse() method

121
Q

How do you store data inlocalStorage?

A

setItem()

122
Q

How do you retrieve data fromlocalStorage?

A

getItem()

123
Q

What data type canlocalStoragesave in the browser?

A

strings

124
Q

When does the’beforeunload’event fire on thewindowobject?

A

Before a document and resources are about to be unloaded