If I write this script :
alert(parseInt(\"123blahblahblah456\"));
I get the alert with the value 123
Ideally, shouldn\'t th
Yes, cf all the anwers. I'd like to add that this is why checking if certain value can be converted to a number, it's better to use Number
or just +
.
Number("123blahblahblah456"); //=> NaN
Number("123"); //=> 123
+"97.221" //=> 97.221
// if the conversion result needs to be an int
Math.round(Number("123.4567")); //=> 123
Be aware though that Number
in some cases (unexpectely) returns 0
.
+null //=> 0
+" " //=> 0
+"" //=> 0
+false //=> 0
+[] //=> 0