HTML and CSS Reference
In-Depth Information
Declaring a JavaScript Variable
• To declare a JavaScript variable, use the statement
varƒ variable ;
where variable is the name assigned to the variable.
• To declare a JavaScript variable and set its initial value, use
varƒ variable ƒ=ƒ value ;
where value is the initial value of the variable.
Using what you've learned about variables, you're ready to add two variables to the
script you started earlier. The first variable, userName, will store the text string cadler ,
which is Catherine Adler's username on the library's mail server. The second variable,
emServer, will store the text string mpl.gov , which is the domain name of the mail server.
Later you'll revise this code to place different values in these variables, but you'll start
with these two fixed values. By breaking up Catherine Adler's e-mail address into two
parts, you'll make it easier to hide the e-mail address from e-mail harvesters later on.
To create two JavaScript variables:
1. Return to the mpl.htm file in your text editor.
2. Locate the script element you created earlier. Directly below the opening
<script> tag, insert the following code, as shown in Figure 10-13:
varƒuserNameƒ=ƒ“cadler”;
varƒemServerƒ=ƒ“mpl.gov”;
Figure 10-13
Declaring javascript variables
3. Save your changes to the file.
Search WWH ::




Custom Search