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.