Object.is() determines whether two values are the same value. Two values are the same if both are undefined, both null, both true or both false, both strings of the same length with the same characters in the same order, both the same object (meaning both values reference the same object in memory), both numbers and both +0, both -0, both NaN, or both non-zero and both not NaN and both have the same value
Parameters: This method accepts the following two parameters:
- value1: It is the first value to compare.
- value2: It is the second value to compare.
Return Value: This function returns the boolean value.
true true false true true false true false
false false true true true true
Key Difference Between Object.is() and === (Strict Equality)
- Object.is(+0,0) is false, Object.is(NaN,NaN) is true.
- So Object.is() is just === with different behavior for negative zero -0 and NaN.
Note: As an ES6 feature, it may not be supported by older browsers, but it can be transpired using Babel for compatibility.
Please Login to comment...