// assignment_02.js console.log("1. 3 is a " + typeof 3 + " (value: " + 3 + ")."); var xanadu = "3"; console.log("2. xanadu is a " +typeof xanadu + " (value: " + xanadu + ")."); xanadu = "3" + 3; console.log("3. xanadu is a " +typeof xanadu + " (value: " + xanadu + ")."); xanadu = "3" - 3; console.log("4. xanadu is a " +typeof xanadu + " (value: " + xanadu + ")."); console.log("5. Question 3 illustrates string concatenation, while Question 4 illustrates arithemetic subtraction.\n"+ "JavaScript converts numbers to strings where possible, but if necessary, it will convert strings to numbers."); xanadu = 3 - xanadu; console.log("6. The value of xanadu is " + xanadu + " and its type is " + typeof xanadu + "."); xanadu = 3 - "xanadu"; console.log("7. The value of xanadu is " + xanadu + " and its type is " + typeof xanadu + "."); console.log("8. Question 6 subtracts the numeric value of xanadu (0) from 3 and produces the numeric result, 3.\n" + "But Question 7 tries to subtract a string that cannot be converted to a number from 3, and cannot;\n" + "the result is not a number, which is the special number NaN."); var Nan = []; console.log("9a. NaN is a " + typeof NaN + " and its value is " + NaN + "."); console.log("9b. 'NaN' is a " + typeof 'NaN' + " and its value is " + 'NaN' + "."); console.log("9c. Nan is a " + typeof Nan + " and its value is " + Nan + "."); console.log("NaN is a special numeric literal which displays as NaN.\n"+ "'NaN' is a string; strings always display as themselves.\n"+ "Nan is a variable holding an empty array, so there is no value to display; arrays are actually specialized objects."); console.log("10. The type of Nan is " + typeof Nan + "."); Nan[0] = 123; console.log("11. Assigning any number, such as 123, to Nan[0], its type becomes " + typeof Nan[0] + "."); console.log("12. The value of 1.23E2 is " + 1.23E2 + " and its type is " + typeof 1.23E2 + "."); console.log("Before Question 13, The type of Nan[3] is " + typeof Nan[3] + ", and Nan.length is " + Nan.length + "."); Nan[3] = function() {}; console.log("13. The type of Nan[3] is " + typeof Nan[3] + ", and Nan.length is " + Nan.length + "."); console.log("14. The type of {} is " + typeof {} + "."); ----------------------------------------------------------------------------------------------------------------------- 1. 3 is a number (value: 3). 2. xanadu is a string (value: 3). 3. xanadu is a string (value: 33). 4. xanadu is a number (value: 0). 5. Question 3 illustrates string concatenation, while Question 4 illustrates arithemetic subtraction. JavaScript converts numbers to strings where possible, but if necessary, it will convert strings to numbers. 6. The value of xanadu is 3 and its type is number. 7. The value of xanadu is NaN and its type is number. 8. Question 6 subtracts the numeric value of xanadu (0) from 3 and produces the numeric result, 3. But Question 7 tries to subtract a string that cannot be converted to a number from 3, and cannot; the result is not a number, which is the special number NaN. 9a. NaN is a number and its value is NaN. 9b. 'NaN' is a string and its value is NaN. 9c. Nan is a object and its value is . NaN is a special numeric literal which displays as NaN. 'NaN' is a string; strings always display as themselves. Nan is a variable holding an empty array, so there is no value to display; arrays are actually specialized objects. 10. The type of Nan is object. 11. Assigning any number, such as 123, to Nan[0], its type becomes number. 12. The value of 1.23E2 is 123 and its type is number. Before Question 13, The type of Nan[3] is undefined, and Nan.length is 1. 13. The type of Nan[3] is function, and Nan.length is 4. 14. The type of {} is object.