|
  
var
The var statement is used to declare variables. This
statement can be used to declare a single variable using the
format
var name ;
It can be used to declare more than one variable at a time
using the format
var name1, name2,...
;
And it can be used with initializers to declare and initialize
variables in a single statement:
var name=expression;
var name1=expression1,name2=expression2,...;
Here are some examples:
var x;
var name,age;
var name="John",age=5;
var x=0,y=1,z;
var square=x*x;
If you don't specify an initializer, the variable is set equal
to null. That is,
var x;
is the same as
var x=null;
Var can also be used inside for
and for/in statements as
follows:
for(var n=0; n<10; n++);
for(var name in object);
|