JavaScript: Variables Flashcards
What is used to declare a variable?
What is an “assignment operator?”
“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 do you re-assign a variable?
Use only the variable’s name
ex: studentName = “Tonya”;
ex: studentAge = 52;
Reminder: Variables created with the const keyword cannot be reassigned.
How do you access a value stored in a variable?
Use the variable’s name
ex: console.log(studentName);
How do you combine the message with a variable value?
Use the template literal syntax.
The code below logs “My name is.”
ex: console.log(“My name is “);
What is “var” in Java Script?
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.