JavaScript’s Object.is
On Primitives and The Importance of ===

This is a very short article as an add-on to Comparing Objects In JavaScript.
At the tail end of that article I mentioned Object.is() and it’s role in comparing Objects.
Thanks to a comment by a reader of that article, I thought I’d mention Object.is() and how it works with primitive data types and not just reference values.
What about Comparing Primitives
One of the statements on the MDN about Object.is(), is,
This is not the same as being equal according to the == operator. The == operator applies various coercions to both sides (if they are not the same Type) before testing for equality (resulting in such behavior as "" == false being true), but Object.is doesn't coerce either value.
That last part about type coercion is important, as well as the difference between the == and === comparison operators.
Example

Conclusion
Make sure you are using the right type of comparison operator.
Remember, the main difference between == and === operators is that == compares variables but performs type coercion. But === doesn’t do that. It checks not only the values but also types of two variables.
Thanks for taking the time to read this!





