ParseInt

From PlainOldWebserver

Jump to: navigation, search

parseInt()

parseInt() shows interesting results, especially when it receives an exponential. In general, it is better to avoid leading parse-able input with alphabetic characters.


 var one = parseInt("3e-3");
 var two = parseInt("23.354");
 var three = parseInt("tr34");
 var four = parseInt("34.4r");
 var five = parseInt(" 34.4 ");
 document.writeln("one is "+one);
 document.writeln("two is "+two);
 document.writeln("three is "+three);
 document.writeln("four is "+four);
 document.writeln("five is "+five);

Result:

 one is 3
 two is 23
 three is NaN
 four is 34
 five is 34
Personal tools
Navigation