Changes

Jump to: navigation, search

Introducing JavaScript Variables

459 bytes added, 18:49, 11 April 2007
Variable Declaration and the Assignment Operator
myVariable = 10;
</pre>
 
It is also possible to declare and assign multiple variables on a single declaration line. For example:
 
<pre>
var i, j, k;
var myValue = 9, myMessage = "Welcome to JavaScript";
</pre>
 
In the first line above the variables ''i'', ''j'' and ''k'' are all defined but assigned values. The second line declared both ''myValue'' and ''myMessage'', initializing the variables with values. In the case of ''myMessage'' the variable is initialized with a string.
== JavaScript Variable Naming Conventions ==
JavaScript variable names are made up of letter, numbers and underscores. They cannot contain spaces and must not begin with a number. For example ''sales_percentage'' would be a valid variable name, where as ''sales percentage'' would be invalid because it contains a space character. Similarly ''two_layers'' is valid, but ''2_layers'' is not due to the fact that it begins with a number. JavaScript variable names can be of any length, although common sense should be used to ensure excessively long name are not used.

Navigation menu