Variable is used to store the value in the physical memory.
Whenever we create the variable some physical memory gets allocated to it.
Syntax of declaring the variable:
There are two ways of declaring the variable:
- Declaring and defining the variable at the same time
- Only declaring and defining in another line
Declaring and defining the variable at the same time:
We can declare and give the value to the variable at the same line.
Only declaring and defining in another line:
We can declare variable in one line and give the value to the variable at somewhere else in the programe but after declaration.
There are three types of keywords by which we can declare the variable:
variables declared with the var keyword are globally and function scoped.
variables are intialized by undefined if declaration is only done.Variables can re-declared.
variables declared with the let keyword are the block scoped.
Variables can re-declared.
variables declared with the const keyword are block scoped.
Variables cannot be re-declared and redefined. Variables should defined at the time declaration.
You don’t have to declare th many variables as it can hold any type of data at the run time.
Sometimes because of run time datatype assignment, it is difficult to find error cause and also it creates confusion.