Declares a variable, optionally initializing it to a value.
Syntax
var varname [= value] [..., varname [= value] ]
Parameters
Parameter | Description |
---|---|
varname | Variable name. It can be any legal identifier. |
value | Initial value of the variable and can be any legal expression. |
Description
The scope of a variable is the current function or, for variables declared outside a function, the current application.
Using var outside a function is optional; you can declare a variable by simply assigning it a value. However, it is good style to use var, and it is necessary in functions in the following situations:
If a global variable of the same name exists.
If recursive or multiple functions use variables with the same name.