Page 199 - JavaScript
P. 199
Empty Array
/* ToNumber(ToPrimitive([])) == ToNumber(false) */
[] == false; // true
When [].toString() is executed it calls [].join() if it exists, or Object.prototype.toString()
otherwise. This comparison is returning true because [].join() returns '' which, coerced into 0, is
equal to false ToNumber.
Beware though, all objects are truthy and Array is an instance of Object:
// Internally this is evaluated as ToBoolean([]) === true ? 'truthy' : 'falsy'
[] ? 'truthy' : 'falsy'; // 'truthy'
Equality comparison operations
JavaScript has four different equality comparison operations.
SameValue
It returns true if both operands belong to the same Type and are the same value.
Note: the value of an object is a reference.
You can use this comparison algorithm via Object.is (ECMAScript 6).
Examples:
Object.is(1, 1); // true
Object.is(+0, -0); // false
Object.is(NaN, NaN); // true
Object.is(true, "true"); // false
Object.is(false, 0); // false
Object.is(null, undefined); // false
Object.is(1, "1"); // false
Object.is([], []); // false
This algorithm has the properties of an equivalence relation:
• Reflexivity: Object.is(x, x) is true, for any value x
• Symmetry: Object.is(x, y) is true if, and only if, Object.is(y, x) is true, for any values x and
y.
• Transitivity: If Object.is(x, y) and Object.is(y, z) are true, then Object.is(x, z) is also true,
for any values x, y and z.
SameValueZero
It behaves like SameValue, but considers +0 and -0 to be equal.
https://riptutorial.com/ 156

