var

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.

Examples

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.