Declares a variable.
The name of the variable being declared.
The initial value assigned to the variable.
Use the var statement to declare variables. You can assign values to the variables when you declare them or later in your script.
A variable is declared the first time it appears in your script.
You can declare a variable without using the var keyword and assign a value to it. This is known as an implicit declaration, and it is not recommended. An implicit declaration gives the variable global scope. When you declare a variable at the procedure level, though, you typically do not want it to have global scope. To avoid giving the variable global scope, you must use the var keyword in your variable declaration.
The following examples illustrate the use of the var statement.
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.