HTML and CSS Reference
In-Depth Information
uppercase letters, by convention only. Constants are assigned values at the time of the
declaration, and it is impossible to modify them during the run of the program. Caveat:
Firefox, Opera, Safari, Netscape, and many browsers support the JavaScript reserved
keyword const to declare constants (see Figure 3.7). It is important to note that Internet
Explorer 7 and 8 do not support it, as shown in Figure 3.8.
EXAMPLE 3.8
<html>
<head><title>Using the const Keyword</title>
<script type="text/javascript">
1
const NOON = 12;
2
const FREEZING = 32;
// Can't change
</script>
</head>
<body bgcolor="silver">
<big>
<script type="text/javascript">
document.write("Farenheit temp is " + FREEZING + ".<br />");
3
FREEZING = 32 + 10;
4
NOON = NOON + " noon";
5
document.write("Make it warmer " + FREEZING + ".<br />");
document.write("See you at ", NOON , ".<br />");
</script>
</big>
</body>
</html>
EXPLANATION
1
The constant NOON is assigned 12, a value that will not change throughout the
execution of this program.
2
The constant FREEZING is assigned 32, a value that will not change throughout
the execution of this program.
3
Now if we try to add 10 to the constant, the value of the constant doesn't change.
It's still 32.
4
This time, we try to concatenate a string to the constant NOON. It will not be
changed.
5
The constants FREEZING and NOON are displayed. They were not changed.
Search WWH ::




Custom Search