Why Object.is() is better than ‘==’ and ‘===’ ?

Maciej Trzciński
Oct 30, 2018 · 1 min read
Anybody reaction for ‘==’ unexpected results :D

Everybody who used JavaScript knows that JS is loosely typed and comparing with ‘==’ gives unexpected results.

So if we use triple equals operator ‘===’, we got a more strict result, but it is also not yet perfect:

For help us in this case we use ES6 ‘Object.is()’, it is more precision than ‘===’ and moreover it behaves well in some special cases:

Compare table:

Polyfill:

Quick Code

Maciej Trzciński

Written by

I have been working in Tonik since 2019. My main fields are: Front-end development and Machine Learning for web solutions. I am from Europe. trzcinski.org

Quick Code

Find the best tutorials and courses for the web, mobile, chatbot, AR/VR development, database management, data science, web design and cryptocurrency. Practice in JavaScript, Java, Python, R, Android, Swift, Objective-C, React, Node Js, Ember, C++, SQL & more.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade