//indexOf()
console.log([1, 2, NaN].indexOf(NaN)); //-1
//includes()
console.log([1, 2, NaN].includes(NaN)); //true
I don't get why includes
can find NaN in array, while indexOf
can't.
I've read that it's happening because indexOf
uses strict-equality-operator internally (NaN === NaN). But as for me, there's no deffirence between strict-equality-operator and abstract equality operator when we're talking about NaN
. NaN
can't be equal to itself anyway.
//strict equality operator
console.log(NaN === NaN); //false
//abstract equality operator
console.log(NaN == NaN); //still false
So why is there some difference between these 2 methods?