According to MDN’s document say that
Note: Technically speaking,
includes()
uses thesameValueZero
algorithm to determine whether the given element is found.
const x = NaN, y = NaN;
console.log(x == y); // false -> using ‘loose’ equality
console.log(x === y); // false -> using ‘strict’ equality
console.log([x].indexOf(y)); // -1 (false) -> using ‘strict’ equality
console.log(Object.is(x, y)); // true -> using ‘Same-value’ equality
console.log([x].includes(y)); // true -> using ‘Same-value-zero’ equality
More detailed explanation:
- Same-value-zero equality similar to same-value equality, but +0 and −0 are considered equal.
- Same-value equality is provided by the Object.is() method: The only difference between
Object.is()
and===
is in their treatment of signed zeroes and NaNs.
Additional resources:
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- Array.prototype.includes vs. Array.prototype.indexOf
- Are +0 and -0 the same?