See the general Sameness concept,
There are four equality algorithms in ES2015:
- Abstract Equality Comparison (
==) - Strict Equality Comparison (
===): used byArray.prototype.indexOf,Array.prototype.lastIndexOf, andcase-matching - SameValueZero: used by
TypedArrayandArrayBufferconstructors, as well asMapandSetoperations, and alsoString.prototype.includesandArray.prototype.includessince ES2016 - SameValue: used in all other places
JavaScript provides three different value-comparison operations:
===: Strict Equality Comparison ("strict equality", "identity", "triple equals")==: Abstract Equality Comparison ("loose equality", "double equals")Object.isprovides SameValue (new in ES2015).
Strict equality compares two values for equality. Neither value is implicitly converted to some other value before being compared. If the values have different types, the values are considered unequal. If the values have the same type, are not numbers, and have the same value, they're considered equal. Finally, if both values are numbers, they're considered equal if they're both not NaN and are the same value, or if one is +0 and one is -0.
Loose equality compares two values for equality, after converting both values to a common type. After conversions (one or both sides may undergo conversions), the final equality comparison is performed exactly as === performs it. Loose equality is symmetric: A == B always has identical semantics to B == A for any values of A and B (except for the order of applied conversions).
Same-value equality addresses a final use case: determining whether two values are functionally identical in all contexts. (This use case demonstrates an instance of the Liskov substitution principle.)
Similar to same-value equality, but +0 and -0 are considered equal.