DEV Community

Kenneth Lum
Kenneth Lum

Posted on • Edited on

How does JavaScript's Object.is() work?

Sometimes you see of frameworks like ReactJS uses Object.is(), and how can you think of it?

It really is just the same as === except two cases:

> 0 === -0
true

> Object.is(0, -0)
false

> NaN === NaN
false

> Object.is(NaN, NaN)
true
Enter fullscreen mode Exit fullscreen mode

Object.is() works just like === except these two cases, so next time when you see Object.is(), you can think of it roughly equivalent to === except these two minor details.

This is in fact the comparison method used in ReactJS Hooks, such as useEffect(), where the dependency array elements are compared using Object.is().

Top comments (0)