HTML and CSS Reference
EXPLANATION ( CONTINUED )
If x is less than y, true is assigned to the variable, result ; otherwise it is assigned false .
The Boolean result of the comparison is displayed by the browser. It is false ; x is
not greater than y .
Figure 5.9 Output from Example 5.6: Numeric comparison.
Comparing Strings. The difference between comparing strings and numbers is that
numbers are compared numerically and strings are compared alphabetically, based on
the ASCII character set. The strings are compared letter by letter, from left to right, and
if they are exactly the same all the way to end, they are equal (see Table 5.10). Once a
letter in one string differs from the corresponding letter in the second string, the com-
parison stops and each of the differing letters is evaluated. For example, if the string
“Dan” is compared with “dan” , the comparison stops at the first letters D and d . “Dan”
is smaller than “dan” , because the letter D has a lower ASCII value than the letter d . D
has an ASCII decimal value of 68, and d has an ASCII value of 100.
built-in string functions, toUpperCase() and toLowerCase(), discussed in section “Free
Form and Reserved Words” on page 33 and Table 9.10 on page 253.
Table 5.10 Comparison Operators
How Operator Compares Strings
"string1" > "string2"
"string1" is greater than "string2"
"string1" >= "string2"
"string1" is greater than or equal to "string2"
"string1" < "string2"
" string1" is less than "string2"
"string1" <= "string2"
"string1" is less than or equal to "string2"