Equality Concept

Equality Operators

In JavaScript there are two ways to test equality/inequality. We can use two equal signs (==) or three equal signs (===). For inequality, it is similar != and !==. So what’s the difference? The difference is type. For example…

This would return true because with a double equal sign, JavaScript converts types. The string of ‘5’ would be converted to a number and the values of each item would be compared. We can avoid this type conversion by using triple equals…

This one would return false because the triple equal signs tells JavaScript to not perform type conversion. Another way to think of it is that it compares not only the value like the double equal sign, but also the type.

Not equal works the same way. A single equal (!=) ignores type while double equals consider type (!==).

Happy Coding!

Clay Hess

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email
Skip to content