HTML and CSS Reference
Name must begin with a letter or underscore
Rest of name must be letters, numerals, or underscores
Name may not use spaces, hyphens, or punctuation
zip.code or zip code
and reserved words
user-defined function, in which case it is considered a local variable. Global means that
the variable value is available for use anywhere inside the HTML file Web page. To define
a variable as global, it must be declared in the <script> section before any of the user-
defined functions. Local means that the variable's value is available only in the function
in which it is defined.
A variable's data type , the type of data it stores, such as text or numbers, must be
data types: numeric, string, date, or Boolean. Numeric data types hold numbers. String
data types are variables that hold characters or a combination of letters, numbers, or symbols.
Date data types contain a date and time. Boolean data types contain logical data that
can be one of two values, such as True/False or Yes/No.
the data type by declaring the variable with an initial value. This feature allows variables to
be flexible and store any data type. Web developers, however, do not recommend chang-
which can be very difficult to find. Table 9-8 shows the general form of declaring a vari-
able and assigning a value to it.
If a variable's value, which
has not been defined or
declared previously, is used
or displayed on the Web
the value “undefined”
to that variable. An
can cause errors in
Table 9-8 Assigning Values to Variables
where var is an optional keyword to designate a variable; variableName is a valid variable name;
and value is the string, numeric, date, or Boolean value being assigned to the variable
var FilmStyle=”Drama” // This variable is a string data type
var length=6.5 // This variable is a numeric data type
var finished=true // This variable is a Boolean data type
In the examples in Table 9-8, the keyword var, meaning variable, appears before the
variable name. A keyword , or reserved word , is a word with special meaning in a pro-
it is good programming practice to precede the variable name with the var keyword the
first time it is defined. In addition, the var keyword is required for local variables defined
within a function.