Page 200 - JavaScript
P. 200
You can use this comparison algorithm via Array.prototype.includes (ECMAScript 7).
Examples:
[1].includes(1); // true
[+0].includes(-0); // true
[NaN].includes(NaN); // true
[true].includes("true"); // false
[false].includes(0); // false
[1].includes("1"); // false
[null].includes(undefined); // false
[[]].includes([]); // false
This algorithm still has the properties of an equivalence relation:
• Reflexivity: [x].includes(x) is true, for any value x
• Symmetry: [x].includes(y) is true if, and only if, [y].includes(x) is true, for any values x and
y.
• Transitivity: If [x].includes(y) and [y].includes(z) are true, then [x].includes(z) is also true,
for any values x, y and z.
Strict Equality Comparison
It behaves like SameValue, but
• Considers +0 and -0 to be equal.
• Considers NaN different than any value, including itself
You can use this comparison algorithm via the === operator (ECMAScript 3).
There is also the !== operator (ECMAScript 3), which negates the result of ===.
Examples:
1 === 1; // true
+0 === -0; // true
NaN === NaN; // false
true === "true"; // false
false === 0; // false
1 === "1"; // false
null === undefined; // false
[] === []; // false
This algorithm has the following properties:
• Symmetry: x === y is true if, and only if, y === xistrue, for any valuesxandy`.
• Transitivity: If x === y and y === z are true, then x === z is also true, for any values x, y and z.
But is not an equivalence relation because
• NaN is not reflexive: NaN !== NaN
https://riptutorial.com/ 157

