HTML and CSS Reference
where variable is the name assigned to the variable. For example, the following state-
ment creates a variable named emLink :
You can declare multiple variables by entering the variable names in a comma-
separated list. The following statement declares three variables named emLink, user-
Name, and emServer:
• The first character must be either a letter or an underscore character (_).
• The remaining characters can be letters, numbers, or underscore characters.
• Variable names cannot contain spaces.
cannot name a variable document.
variable names emLink and emlink represent two different variables. One common
programming mistake is to forget this important fact and to use uppercase and lowercase
letters interchangeably in variable names.
To avoid programming
errors, use a consistent
pattern for case in vari-
Assigning a Value to a Variable
Once a variable has been created or declared, you can assign it a value. The statement to
assign a value to a variable is
variable ƒ=ƒ value ;
where variable is the variable name and value is the value assigned to the variable. For
example, the following statement stores the text string cadler in the userName variable:
You can combine the variable declaration and the assignment of a value in a single
statement. The following statements declare the userName and emServer variables, and
set their initial values:
lowing statement both creates the director variable (if it has not already been declared in
a previous statement) and assigns it an initial value:
To make your code easier
to interpret, place all of
your variable declara-
tions at the beginning of
Although it's not required, it's considered good programming style to use a var state-
ment to declare all of your variables. Doing so helps you keep track of the variables a
program uses and also makes it easier for others to read and interpret your code.