JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store bits of 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

With a variable keyword (var, let, const) followed by 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

With an 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, digits, underscores and dollar signs (CANNOT START WITH NUMBER)

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

upper and lowercase matter

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 store text data

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 store number data

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

Assignment operator

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

By calling again with the assignment operator followed by the new 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 usually a placeholder

Undefined points at valueless variables

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

Describes the variable or value being logged

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
Boolean
Object
Undefined
Null

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

When two or more lines of strings are combined using the addition 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

Adds one value to another

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 represent real world objects

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

What are object properties?

A

Information about the object

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

How do you remove a property from an object?

A

With the delete operator

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

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

A

Dot and Bracket notation

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

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

Describe array literal notation.

A

var arrayName = [’’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How are arrays different from "plain" objects?
Arrays have indexes objects dont
26
What number represents the first index of an array?
array[0]
27
What is the length property of an array?
Represents the number of properties in that array
28
How do you calculate the last index of an array?
array[array.length -1]
29
What is a function in JavaScript?
A pack of code to reuse
30
Describe the parts of a function definition.
function funcName(parameter,/.../,parameter) { code .../ return; code .../ }
31
Describe the parts of a function call.
funcName(parameter,/.../,parameter);
32
When comparing them side-by-side, what are the differences between a function call and a function definition?
No code block
33
What is the difference between a parameter and an argument?
Arguments are real values being passed to the function, while parameters are just placeholder names
34
Why are function parameters useful?
Specify what the argument should be
35
What two effects does a return statement have on the behavior of a function?
Returns the function when being called Stops the code from running
36
Why do we log things to the console?
To check our work
37
What is a method?
Function of an object
38
How is a method different from any other function?
It's a property of an object
39
How do you remove the last element from an array?
With the array.pop(); method
40
How do you round a number down to the nearest integer?
With the Math.floor() method
41
How do you generate a random number?
With the Math.random(); method
42
How do you delete an element from an array?
With the array.splice(index,amount);
43
How do you append an element to an array?
With the push(); method
44
How do you break a string up into an array?
With the split() method
45
Do string methods change the original string? How would you check if you weren't sure?
They dont
46
Roughly how many string methods are there according to the MDN Web docs?
Around 50
47
Is the return value of a function or method useful in every situation?
No, you may use it later on
48
Roughly how many array methods are there according to the MDN Web docs?
40-50
49
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
50
What data type do comparison expressions evaluate to?
Booleans
51
What is the purpose of an if statement?
To execute a block of code when the condition is met or not
52
Is else required in order to use an if statement?
else
53
How do you compare two different expressions in the same condition?
&& ||
54
What is the purpose of a loop?
Easy way to do something repeatedly
55
What is the purpose of a condition expression in a loop?
To let it know when to start and stop
56
What does "iteration" mean in the context of loops?
To repeat
57
When does the condition expression of a while loop get evaluated?
At the beginning
58
When does the initialization expression of a for loop get evaluated?
At the very start
59
When does the condition expression of a for loop get evaluated?
After every initialization and after every loop
60
When does the final expression of a for loop get evaluated?
After the iteration
61
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
The Break; Key
62
What does the ++ increment operator do?
Increment the value by one
63
How do you iterate through the keys of an object?
With a for in loops for ( var prop in obj ) { code }
64
Why do we log things to the console?
To keep track that everything is working.
65
What is a "model"?
A "model" is a memory saved model created with nodes representing an HTML element (DOM tree)
66
Which "document" is being referred to in the phrase Document Object Model?
The HTML document currently being worked on
67
What is the word "object" referring to in the phrase Document Object Model?
DOM Tree nodes
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.
querySelectorAll()
70
Why might you assign the return value of DOM query to a variable?
To refer back to it
71
What console method allows you to inspect the properties of a DOM element object?
console.dir()
72
Why would