JavaScript > Number

Redjini WiKi


x = true;
Number(x);        // returns 1

x = false;     
Number(x);        // returns 0

x = new Date();
Number(x);        // returns 1404568037939 == x.getTime()

x = "10"
Number(x);        // returns 10

x = "10 20"
Number(x);        // returns NaN
parseInt Method
parseInt("10");         // returns 10
parseInt("10.33");      // returns 10
parseInt("10 20 30");   // returns 10
parseInt("10 years");   // returns 10
parseInt("years 10");   // returns NaN
parseFloat Method
parseFloat("10");        // returns 10
parseFloat("10.33");     // returns 10.33
parseFloat("10 20 30");  // returns 10
parseFloat("10 years");  // returns 10
parseFloat("years 10");  // returns NaN