I stumbled over this polyfill of Array.prototype.includes. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes. Is there a reason for the comparison of the variables with themselves on line 21,22?
if (searchElement === currentElement ||
(searchElement !== searchElement && currentElement !== currentElement)) {
return true;
}
Yes, this second operand of the
||does check whether bothsearchElementandcurrentElementareNaN- the only value in JavaScript that is not===to itself.includesis supposed to use theSameValueZeroequivalence algorithm, which is different from the the Strict Equality Comparison Algorithm (used by===) or theSameValuealgorithm (used inObject.is).