JavaScript: Variables Flashcards

1
Q

What is used to declare a variable?
What is an “assignment operator?”

A

“let” declares student variable. If the value of the variable will change, use the let keyword.

ex: let studentName;

Then use an assignment operator(=) to assign a value

ex: let studentAge = 32;

Alternatively, if the value of the variable will not change, use the const keyword.

ex. const teacherName = “Abdul”;

It is recommended to default to using “const” over “let”

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

How do you re-assign a variable?

A

Use only the variable’s name

ex: studentName = “Tonya”;
ex: studentAge = 52;

Reminder: Variables created with the const keyword cannot be reassigned.

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

How do you access a value stored in a variable?

A

Use the variable’s name

ex: console.log(studentName);

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

How do you combine the message with a variable value?

A

Use the template literal syntax.
The code below logs “My name is.”

ex: console.log(“My name is “);

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

What is “var” in Java Script?

A

Traditionally, the var keyword was used to create variables, but modern javaScript has replaced it with let/const.

ex. var teacherAge = 48;

You might see this in older code.

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