Declares a variable(s) that allows us to store some information that we may want to manipulate or use later. The variable is like a container where we put our information for later retrieval.
- Variable scope is the current function for variables declared within a function, or the current application for variables declared outside a function.
|Declares a variable(s) that allows us to store some information that we may want to manipulate or use later. The variable is like a container where we put our information for later retrieval.|
|Can be any legal identifier as outlined below:
|An initial value which can be any legal expression.|
The code below creates two undefined variables called
var aVariable; var bVariable;
Creates a variable called
aVariable and assigns the value 25 to it. Creates a variable called
bVariable and assigns the value 'candles' to it and the concatenates the two variables for display.
var aVariable = 25; var bVariable = 'Candles'; alert(aVariable + bVariable);
You can also create multiple variables at the same time by delimiting the end of each variable name with the comma (,) symbol.
// Create three variables. var aVariable, bVariable, cVariable; // Create three variables with initial value of 0. var aVariable = 0, bVariable = 0, cVariable = 0;