Chapter 5 exercise 4a

4. a. Are the following true or false?

1.) 22 == "22" : Two strings are equal when they have the same sequence of characters, same length, and same characters in corresponding positions. Two numbers are equal when they have the same numeric value. If a string is compared with a number, they are equal if the number has the same characters as the string. Thus this is TRUE.

2.) 22 === "22" : One is a numerical data type and the other is a string data type;They not only must be of the same value, but also of the same data type. Thus this is FALSE.

3.) "2" > "100" : 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. Once a letter in one string differs from the corresponding letter in the second string, the comparison stops and each of the differing letters is evaluated. Thus this is TRUE the "1" equals ASCII 49 and "2" equals 50 ASCII.

Complete chapter 5 exercise 4a. Use the document.write method to show the values of the 3 expressons. Comment each expression in your code explaining why the true or false value was returned. Save this page as chapt5ex4a.html in your week 3 folder.




Back to Assignment Web Page.

Valid XHTML 1.0!

Valid CSS!

W3C XHTML validation page

W3C CSS Validation Page