HTML and CSS Reference
In-Depth Information
EXPLANATION
6
The value
null
is assigned to the variable called
job_title
.
Null
is used to set a vari-
able to an initial value different from other valid types, but if used in an expression
the value of
null
will be converted to the appropriate type.
7
The document head ends here.
8
The body of the document starts here.
9
A new JavaScript program starts here. All the variables declared in the head of the
document are available here. Variables that are available throughout the entire
document are called global variables.
10
The
document.write()
method concatenates the values of the strings with the +
sign and sends them to the browser to display on the screen.
11
The value of the variable called
age
is displayed.
12
The variable called
ssn
was declared, but not initialized. It has no value, which
JavaScript calls
undefined
.
13
The variable
job_title
was assigned
null
, a placeholder value. The
null
string is re-
turned.
14
The variable
ssn
is assigned a string value. It is no longer
undefined
. Even though
the variable was declared in the head of the document, as long as it was declared,
it can be assigned a value anywhere else in the document.
15
The value of the variable
ssn
is displayed. Figure 3.6 shows the output in Internet
Explorer.
Figure 3.6
Declaring and displaying variables.