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
Describe array literal notation
Var is defined opening brace for the code block string, numbers, or booleans separated by commas closing brace for the code block semicolon
26
How are arrays different from "plain" objects?
Instead of properties with their own unique key value pairs, the key for each value in an array is represented by its index number
27
What number represents the first index of an array?
0
28
What is the length property of an array?
The number of items in the array
29
How do you calculate the last index of an array?
Array[Array.length - 1]
30
What are objects used for?
Storing multiple functions or attributes of an item
31
What are object properties?
Key value pairs
32
Describe object literal notation.
A variable being defined Start of the code block Properties made of key value pairs separated by commas Closing of the code block Semicolon
33
How do you remove a property from an object?
Delete obj.property
34
What are the two ways to get or update the value of a property?
Dot notation and bracket notation
35
What is a function in JavaScript?
A block of code that executes a task and can easily be called on
36
Describe the parts of a function definition.
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
37
Describe the parts of a function call.
The functions name, 0 or more arguments separated by commas enclosed in parentheses
38
When comparing them side-by-side, what are the differences between a function call and a function definition?
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
39
What is the difference between a parameter and an argument?
A parameter is part of a function definition and an argument is part of the function call
40
Why are function parameters useful?
It acts as a placeholder until you have the actual values when the function is called
41
What two effects does a return statement have on the behavior of a function?
It produces a value from the function It ends the function code block from running anything else
42
Why do we log things to the console?
Using the log method of the console object console.log();
43
What is a method?
A function inside of an object
44
How is a method different from any other function?
It is part of an object while other functions are not
45
How do you remove the last element from an array?
Pop method (shift method to remove first element)
46
How do you round a number down to the nearest integer?
Math.floor();
47
How do you round a number down to the nearest integer?
Math.floor();
48
How do you generate a random number?
Math.random() The random method of the Math object
49
How do you delete an element from an array?
Splice method (first number is which index to before which index to start at, second number is how many elements to remove)
50
How do you append an element to an array?
Push method to add to end of array. Unshift method to add to beginning of array
51
How do you break a string up into an array?
Split method
52
Do string methods change the original string? How would you check if you weren't sure?
No they can only split or concatenate the string or capitalize it. You can log it to the console to check
53
Roughly how many string methods are there according to the MDN Web docs?
About 50
54
Is the return value of a function or method useful in every situation?
No because some methods may give a random value
55
Roughly how many array methods are there according to the MDN Web docs?
About 40
56
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
57
Give 6 examples of comparison operators.
>, >=, <, <=, !==, ===
58
What data type do comparison expressions evaluate to?
Boolean
59
What is the purpose of an if statement?
To run different blocks of code based on if that block of code meets a condition
60
Is else required in order to use an if statement?
No, if you only need the code to run if the condition is true
61
Describe the syntax (structure) of an if statement.
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
What are the three logical operators?
&& logical and, || logical or, ! Logical not
63
How do you compare two different expressions in the same condition?
By using a logical operator in between them
64
What is the purpose of a loop?
It checks a condition until it returns false
65
What is the purpose of a condition expression in a loop?
It checks to see if the code should run again or to stop
66
What does "iteration" mean in the context of loops?
It is each time the loop runs
67
When does the condition expression of a while loop get evaluated?
The beginning of each loop until the condition is not met
68
When does the initialization expression of a for loop get evaluated?
It is evaluated before the code block runs for the first time
69
When does the condition expression of a for loop get evaluated?
It is evaluated at the beginning of each loop iteration
70
When does the final expression of a for loop get evaluated?
it is evaluated at the end of each loop iteration
71
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Keyword break
72
What does the ++ increment operator do?
It adds one to the counter every time the loop runs and drives the loop until it no longer runs
73
How do you iterate through the keys of an object?
using for in loop
74
What event is fired when a user places their cursor in a form control?
Focus Event
75
What event is fired when a user's cursor leaves a form control?
Blur event
76
What event is fired as a user changes the value of a form control?
input event
77
What event is fired when a user clicks the "submit" button within a ?
Submit event
78
What does the event.preventDefault() method do?
It prevents the browser from following through the the events normal actions
79
What does submitting a form without event.preventDefault() do?
It will reload the page
80
What property of a form element object contains all of the form's controls.
Elements property
81
What property of a form control object gets and sets its value?
Value property
82
What is one risk of writing a lot of code without checking to see if it works so far?
you will have to backtrack to find your mistake
83
What is an advantage of having your console open when writing a JavaScript program?
You can check if everything is working properly and debug as you go
84
What are objects used for?
Storing multiple methods or properties of an item
85
What are object properties?
Key value pairs that are attributes of that object
86
Describe object literal notation.
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
How do you remove a property from an object?
delete object.property
88
What are the two ways to get or update the value of a property?
dot notation and bracket notation
89
Why do we log things to the console?
check our work and to debug
90
What is a method?
a function inside of an object
91
How is a method different from any other function?
It is part of an object while other functions are not
92
How do you remove the last element from an array?
pop method
93
How do you round a number down to the nearest integer?
Math.floor()
94
How do you generate a random number?
splice()
95
How do you append an element to an array?
push()
96
How do you break a string up into an array?
split()
97
Do string methods change the original string? How would you check if you weren't sure?
No they can only split or concatenate the string or capitalize it. You can log it to the console to check
98
Roughly how many string methods are there according to the MDN Web docs?
About 50
99
Is the return value of a function or method useful in every situation?
no because some methods may give a random value?
100
Roughly how many array methods are there according to the MDN Web docs?
About 40
101
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
102
Give 6 examples of comparison operators.
>, >=, <, <=, !==, ===
103
What data type do comparison expressions evaluate to?
Boolean
104
What is the purpose of an if statement?
To run different blocks of code based on if that block of code meets a condition
105
Is else required in order to use an if statement?
No, if statement will always be true
106
Describe the syntax (structure) of an if statement.
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
What are the three logical operators?
&& logical and, || logical or, ! logical not
108
How do you compare two different expressions in the same condition?
By using a logical operator in between them
109
What is the event.target?
It is the element that the target was triggered from
110
What is the affect of setting an element to display: none?
The element will disappear from the webpage
111
What does the element.matches() method take as an argument and what does it return?
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
How can you retrieve the value of an element's attribute?
getAttribute method
113
At what steps of the solution would it be helpful to log things to the console?
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
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?
We would need to make a separate event listener for the new tab and view divs.
115
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?
We would have to write a long list of if else statements and check conditions for each index of the nodelists
116
What is JSON?
Text format for representing javascript object syntax
117
What are serialization and deserialization?
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
Why are serialization and deserialization useful?
Provides a useful method to transport data from one place to another
119
How do you serialize a data structure into a JSON string using JavaScript?
The JSON.stringify() method
120
How do you deserialize a JSON string into a data structure using JavaScript?
The JSON.parse() method
121
How do you store data in localStorage?
setItem()
122
How do you retrieve data from localStorage?
getItem()
123
What data type can localStorage save in the browser?
strings
124
When does the 'beforeunload' event fire on the window object?
Before a document and resources are about to be unloaded