Datatypes and variable declaration
We need to store our values with datatypes ("string", numbers, boolean,bigint, symbol, objects, undefined) into some reserved keywords. Storing a value in a variable is called variable initialization or declaration. You can do variable initialization at the time of variable creation or at a later point in time when you need that variable.
Each keyword behaves differently and we need to study about each in depth to understand Javascript completely.
Var keyword
Var keyword is used to declare the values. we can re-assign the value with Var keyword. It is a global scope. When it is hoisted its value is undefined in the temporal deadzone.
Syntax:
Here, we were able to re-assign x value.
Naming Convention
All JavaScript variables must be identified with unique names.
- These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs.
- Names must begin with a letter
- Names can also begin with $ and _ (but we will not use it in this tutorial)
- Names are case sensitive (y and Y are different variables)
- Reserved words (like JavaScript keywords) cannot be used as names
Let keyword
Let keyword is used to declare the values. We can re-assign the value with let keyword. It is a function
scope and block scope. It cannot be hoisted
Const keyword
Const keyword is used to declare the values. We cannot re-assign the values with Const keyword. It is a function scope and block scope. It cannot be hoisted