- The alliance of Netscape and Sun Microsystems did not use Java in the browser, because it was not suitable for that purpose. Why do you think Java was not suitable to be embedded in a browser?
- When parsing a String into a number using the parseInt() method, we are advised to always provide the radix. Why is it so strongly recommended?
- What is a type, and why do you think types are useful in writing programs?
- Why do we lose precision when performing operations with decimal numbers in Javascript? Can you think of a few implications of why this would be a problem?
- Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500
- What does
typeof 4.5
do, and why doestypeof (typeof 4.5)
return "string"
Java was probably not suitable to be embedded in a browser because it was too large and clunky, unsuited for running quick and tight small pieces of code. Also, the programs would have to be embedded, compiled code, whereas the rest of the web was in plaintext.
Radix ensures that the conversion ensures that the base is the one you want. On occasion, Javascript will think you mean base 8, for instance.
A type is an int, double, boolean, string, etc. It is a 'type' of data. It is useful because we can force the program to check if the proper type is being returned, and that you run programs that make sense using those inputs.
You have to be careful about using decimal numbers, because they are stored as doubles which are by their nature imprecise. Of course, they are only imprecise to .0000 ... 01, but that still makes a difference on occasion.
Order of operations
typof 4.5 will return a "double" (the 'type' of the number) which in itself is a string.
My code assignment is hosted here: http://code.google.com/p/p2pu-javascript/