JS Primitives & Variables Flashcards

1
Q

What is the purpose of variables?

A

To store data. Data is able to continue to exist under a name and can be referred back to.

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

How do you declare a variable?

A

First use a variable keyword (such as “var” or “let” or “const”) and then followed by a 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
By using the assignment operator (=):
(i.e.  var name = value)
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

Must begin with a letter, $, or _.
Cannot start with a number.
Cannot use dash ( - ) or period ( . ).

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

The computer will read the variable as a different variable even with one letter off. Uppercase and lowercase are different.

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 characters that have meaning somewhere but not in JavaScript.

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

For tasks that involve counting or calculating sums.

Also for moving elements or resizing elements.

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

It was two values “true” or “false”. It serves as kind of like a light switch — can turn on or off a script.

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

It is an assignment operator. It does not mean equal. ( === means equal )

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

It will not need a variable keyword anymore. Simply state the variable name followed by the assignment operator and 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 is an object and undefined is undefined.
Null is purposely put there by a developer indicating something will be put there later.
Undefined is from computer.

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

So you or other developers know which variable or value is being logged.
It can be less confusing when debugging.

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, number, boolean, undefined, null

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