javascript-primitives-and-variables Flashcards

1
Q

What is the purpose of variables?

A

to store data/info for the script

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 name; keyword is var and following it is 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

variableName = x;

assign a value (x) to the variable name using 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

dollarsign ($) and underscore (_), letters and numbers

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 cases (capital letters, lowercase letters) matter; so “Yes” and “yes” would be different variable names

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 put any value inside of quotation marks; text values

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 input numbers as values

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 has two values: true or false; it is to tell whether to run a script or not to make decisions

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 the assignment operator, meaning it will assign a value to a variable

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

input the variable name and assign it the new value; no need to declare the var again. Ex: name = “newValue”

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 when someone actually declared a variable as a null value, while undefined hasn’t been defined by anyone and so has no value

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

to be able to tell what the value is for; easier to debug

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