The JavaScript var statement declares a JavaScript variable. Optionally, you can use the = assignment operator to initialize a variable at the same time that you create it. The JavaScript variable definition uses the following syntax:
var variable_name [= initial_value];
The following lines create variables but leave the initial values undefined until subsequent code assigns values to them:
var x var s
You can initialize a variable as either an integer or a string. In the following example, x is initialized as an integer and s is initialized as an empty string.
var x = 0 var s = ""
You can create multiple variables in a single statement:
var i = 0, j = 0, k = 0
|
Copyright © 2013 CA.
All rights reserved.
|
|