August 2012
Beginner
583 pages
16h 1m
English
Unlike PHP, JavaScript has no explicit casting of types such as
(int) or (float). Instead, when you need a value to be of
a certain type, use one of JavaScript’s built-in functions, shown in Table 14-6.
Change to type | Function to use |
Int, integer | |
Bool, Boolean | |
Float, double, real | |
String | |
Array | |
So, for example, to change a floating-point number to an integer,
you could use code such as the following (which displays the value
3):
n = 3.1415927 i = parseInt(n) document.write(i)
Or you can use the compound form:
document.write(parseInt(3.1414927))
That’s it for control flow and expressions. The next chapter focuses on the use of functions, objects, and arrays in JavaScript.
Read now
Unlock full access