Object.is()
provides a true comparison for any object. Start using it today if you have missed out so far..!
Consider the code below -
|
|
While we are ok with the statements above break
, the statements below can cause a problem.
Typically this is overcome by using strict comparison -
|
|
But, what about the only edge case that is so.. so.. so important -
|
|
Will you use ==
, ===
, invent your own ====
, or just get flustered enough to ignore the edges?
Now* you may not do any of those things. Object.is()
is here.
Object.is()
not only solves the most common equality problems..
|
|
But also, solves the ‘super important’, ‘most commonly used’ edge cases.
|
|
Simply do Object.is
everywhere and sleep peacefully at night..
Or.. no. Hold on a minute - how about those pesky objects?
|
|
Objects still work on the same principle - you need to manually compare values. Object.is()
cannot convert the reference properties of an object magically. Give it a break, y’all.
* now = circa ES6. I am late to the party, can’t keep track of everything now.