Wednesday 31 March 2021

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?



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

No comments:

Post a Comment