-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Description
MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
What information was incorrect, unhelpful, or incomplete?
In the article (Under Number) it says that "You can test for NaN using the built-in isNaN() function:"
However, this fuction also returns true on lots of other inputs, other than NaN
isNaN('hello') // true
isNaN(function(){}) // true
isNaN({hello: 'world'}) // true
But other than that, it is inconsistent as well:
isNaN([1]) // false
isNaN([1,2]) // true
isNaN('1') // false
Specific section or headline?
under Numbers / You can test for NaN using the built-in isNaN() function:
What did you expect to see?
Instead of isNaN, Number.isNaN produces the expected result:
Number.isNaN('hello') // false
Number.isNaN(function(){}) // false
Number.isNaN({hello: 'world'}) // false
Number.isNaN([1,2]) // false
Browser support is a little bit worse for Number.isNaN when compared to isNaN but it's supported in all the current browsers, plus that if you actually need it, you can always use a polyfill, as seen on
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN#polyfill
Did you test this? If so, how?
Using Chrome DevTools
MDN Content page report details
- Folder:
en-us/web/javascript/a_re-introduction_to_javascript - MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
- GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html
- Last commit: 3b80812
- Document last modified: 2021-02-19T19:57:02.000Z