Variables Flashcards
What is let ?
One of the keyword used when you want to declare a variable that is might be reassigned
What is const ?
One of the keyword used when you want to declare a variable with a constant value
What are the keywords possible for a variable?
Var : used pre-ES6 versions of JS
Let : variable can be reassigned a different value
Const : variable cannot be reassigned because it is constant
What happens when a variable has not been initialized ?
The primitive data type is going to be store undefined
What happens if you try to reassign a
const variable?
You’ll get aTypeError
What happens if you try to declare aconstvariable without a value?
You’ll get aSyntaxError
When do you get aSyntaxError?
If you try to declare a const variable without a value
When do you get a TypeError?
If you try to reassign aconstvariable
When do you get automatically a value ofundefined?
If we don’t assign a value to a variable declared using theletkeyword
What happens If we don’t assign a value to a variable declared using theletkeyword?
It automatically has a value of undefined
What are the few general rules for naming variables?
- Variable names cannot start with numbers.
- Variable names are case sensitive, so
myName
andmyname
would be different variables. It is bad practice to create two variables that have the same name using different cases. - Variable names cannot be the same askeywords.
What is = ?
An assignment operator
What is what ?
var myName =’Arya’;
-
var
, short for variable, is a JavaScriptkeywordthat creates, ordeclares, a new variable. -
myName
is the variable’s name. -
=
is theassignment operator. It assigns the value ('Arya'
) to the variable (myName
). -
'Arya'
is thevalueassigned (=
) to the variablemyName
What is a variable?
Avariableis a container for a value.
Variables also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves.
In short, variables label and store data in memory
What can you do with variables ?
- Create a variable with a descriptive name.
- Store or update information stored in a variable.
- Reference or “get” information stored in a variable.
What are NOT variables?
Variables are not values
What is var ?
Var : used pre-ES6 versions of JS
Short for variable, is a JavaScriptkeywordthat creates, ordeclares, a new variable.
What is the increment operator ?
It’s ++
What is the decrement operator ?
It’s –
What are The Increment and Decrement Operator?
They are two of mathematical assignment operators. You can use them to update the variable’s valueandassigned as the new value of that variable.
Increment operator is (++)
Decrement operator is(–).
Mathem
We can use variables and math operators to calculate new values and assign them to a variable
How can we use the + operator?
The+operator is used to concatenate strings including string values held in variables.
What do you use to interpolate values into a string ?
Template literals use backticks`and${}
What is thetypeofkeyword for ?
Returns the data type (as a string) of a value.