Inconsistencies with Javascript isNaN()
I've just been reading that there are apparently some inconsistencies with how isNaN handles things and is therefore not completely reliable. Strange. In ES6 Number.isNaN() has some improvements over the built in isNaN() in that regard. However, I did a few quick tests: var a = Number.isNaN(1); // false var b = isNaN("hi"); // true var c = Number.isNaN("hi"); // false <<< should be true! var d = isNaN(NaN); // true var e = Number.isNaN(NaN); // true console.log(a, b, c, d, e) It seems that there are still inconsistencies. So, is there some other solution to test for numbers? I've thought of these things but I wonder if there are some other methods. Possible Solution to inconsistencies with isNaN: - use parseFloat(). It will result in NaN if not a number. Question: is it fast? - all numbers should be divisible by one. A `string` or `NaN` will result in `NaN` when divided by 1.