A variable is a name associated with a data value. The variable store or contains the value. Thus a variable allows us to store and manipulate data in our program.
Example var variablename; var i;
We can declare multiple variable with same var keyword:
Example var i, sum, j;
We can also assign a value to the variable at the of declaration. This is called initialization. Initialization is done by using “=” equal operator.
Example var variablename = initialvalue; var i=10;
There are few rules for naming a variable.
- It must start with a letter or underscore.
- It may contain letters, digits and underscore in any compilation.
- It may not contain blank, space or comma.
- It may not contain special character.