DEV Community

Cover image for Why is better than ‘==’ and ‘===’ ?
Maciej Trzciński 🌱🇵🇱
Maciej Trzciński 🌱🇵🇱

Posted on • Updated on • Originally published at Medium

Why is better than ‘==’ and ‘===’ ?

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 ‘’, it is more precision than ‘===’ and moreover it behaves well in some special cases:

Compare table:



If you like this article, follow me on Twitter @MaciejDEV

Top comments (4)

codefinity profile image
Manav Misra

I had 4gotten about this. === really is 'good enough' - less typing than - Besides those edge cases, NS 😕 if it's worth it?
GTK, though. JIC.

aqrojo profile image

Yes, all that tests return false when you use '==='

' ' == 0 //false
null == undefined //false
[1] == true //false
Enter fullscreen mode Exit fullscreen mode
prox_sea profile image
Eduardo Zepeda

Thank you so much for your post!

sidthesloth92 profile image
Dinesh Balaji

Nice post. I believe you have misplaced === code snippet with == (The second snippet)..:)