0

what is the difference between isNaN and Number.isNaN?

isNaN('hello world'); // returns 'true'.
Number.isNaN('hello world'); // returns 'false

1 Answers1

0

The spec is a good place to turn for this kind of subtlety. isNaN tries to convert its argument to a number; Number.isNaN doesn't, it returns false if the type of its argument isn't "number". So:

console.log(isNaN("%"));        // true, coerced to number and result was NaN
console.log(Number.isNaN("%")); // false, not coerced
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875