JavaScript provides three different values for comparison operations:
- Strictly equal ("triple equals" or "identity"), use = = =,
- Loosely equal ("double equals"), using = =
- and
Object.is
(ECMAScript 2015/es6 new features)
In short, when comparing two things, the double equals sign performs the type conversion; The three equals sign will make the same comparison without a type conversion (if the type is different, only false is always returned); The object.is behaves the same as the three equals, but for NaN and 0 and +0, the last two are different, and object.is (Nan,nan) will be true
. (You typically use a double or three equals sign to compare Nan with Nan, and the result is false, because IEEE 754 says.) Please note that all of these differences are related to their handling of the primitives; None of the three primitives of the operators will compare two variables with similar structural concepts. For any two different non-primitive objects, even if they have the same structure, the above three operators will be evaluated to false.
When to use object.is or third-level
Object.is will judge the object property description, if you do not need to judge the description of the attribute should take precedence of the use of three-
object Property Description ReferenceObject.defineProperty
JS equal Judgment (==,===,object.is)