Skip to main content Accessibility Feedback

Equals (==) vs Strict Equals (===) in JavaScript

You might have noticed that equal comparisons can be written two different ways: equals (==) and strict equals (===).

So what’s the difference?

Strict equals checks if the two items are the same type. Regular equals does not. For example…

// returns true
(42 == '42')

// returns false
(42 === '42')

If you don’t want to check type (for example, if the user could pass in a string or a number and that’s ok) use equals. Otherwise, default to strict equals.


🚀 Make 2018 the year you master JavaScript! My pocket guides and mini courses are short, focused, and made for beginners. You can do this!

Have any questions or comments about this post? Email me at chris@gomakethings.com or contact me on Twitter at @ChrisFerdinandi.

Get Daily Developer Tips