JavaScript provides three different value-comparison operations:
===— strict equality (triple equals)==— loose equality (double equals)Object.is()
Which operation you choose depends on what sort of comparison you are looking to perform. Briefly:
- Double equals (
==) will perform a type conversion when comparing two things, and will handleNaN,-0, and+0specially to conform to IEEE 754 (soNaN != NaN, and-0 == +0); - Triple equals (
===) will do the same comparison as double equals (including the special handling forNaN,-0, and+0) but without type conversion; if the types differ,falseis returned. Object.is()does no type conversion and no special handling forNaN,-0, and+0(giving it the same behavior as===except on those special numeric values).
They correspond to three of four equality algorithms in JavaScript:
- IsLooselyEqual:
== - IsStrictlyEqual:
=== - SameValue:
Object.is() - SameValueZero: used by many built-in operations
Note that the distinction between these all have to do with their handling of primitives; none of them compares whether the parameters are conceptually similar in structure. For any non-primitive objects x and y which have the same structure but are distinct objects themselves, all of the above forms will evaluate to false.


One Response
Good Blog