Tuesday, December 20, 2016

parseInt() and parseFloat() function

The parseInt() and parseFloat() functions parse a string until they reach a character that isn't valid for the specified number format, then return the number parsed up to that point. However the "+" operator simply converts the string to NaN if there is an invalid character contained within it. Just try parsing the string "10.2abc" with each method by yourself in the console and you'll understand the differences better.

+ "42"; // 42
+ "010"; // 10
+ "0x10"; // 16

isNaN(NaN); // true
isFinite(1/0); // false
isFinite(-Infinity); // false
isFinite(NaN); // false

@reference_0_mozilla


No comments:

Post a Comment