2021年3月25日星期四

Why does [NaN].includes(NaN) return true in JavaScript?

I'm familiar with NaN being "weird" in JavaScript, i.e., NaN === NaN always returns false, as described here. So one should not make === comparisons to check for NaN, but use isNaN(..) instead.

So I was surprised to discover that

> [NaN].includes(NaN)  true  

This seems inconsistent. Why have this behavior?

How does it even work? Does the includes method specifically check isNaN?

https://stackoverflow.com/questions/66743472/why-does-nan-includesnan-return-true-in-javascript March 22, 2021 at 05:35PM

没有评论:

发表评论