Variable

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.

JavaScript un-typed or loosely typed language i.e. we need not explicitly specify the datatype of a variable when we create it. The some variable may be used to hold different types of data at different time when the java script code runs.

In JavaScript, a variable is declared using var keyword:

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.

Leave a Reply