Re:NPM Vulnerability Discussion on Twitter
by __s on Tuesday May 10, 2022 @09:36AM
(#31326950)
& ofc there's https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
[ Parent
| on HN ]
Which wasn't everywhere in 2017, when isnan was created: IE11 didn't (and still doesn't, though it's less relevant) have isNaN()
(Not supporting a culture of taking a dependency for this sort of thing, though)
Just to be clear, because your comment made no sense to me: what IE11 doesn't support is Number.isNaN(). It definitely does support (and has since IE3) plain isNaN(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Regular isNaN is very tricky, and almost never what you want: it first coerces its input to a Number, and then checks if that is NaN:
isNaN Number.isNaN
----- ------------
{} true false
[true] true false
undefined true false
"{}" true falseBut none of those things you listed are numbers. The isNaN output is exactly what I want in pretty much every case.