DEV Community

Cover image for What the f#$k is strict equality.
Eduardo Henao
Eduardo Henao

Posted on

What the f#$k is strict equality.

Sometimes I see some memes regarding Javascript equality and yeah, some of them are pretty funny, here is my favorite.

Image description

I see that there is a common pattern, this "weird" behavior always happens with the double equal sign operator == which we can call loose equality. This happens because it perfoms the IsLooselyEqual algorithm, and the Javascript engine will perform a typer cohertion to try to match both sides in type and value.

How can avoid these "weird" behavior?

Well when you use the triple equal operator === javascript doesn't convert at all the type of your values, and then performs a comparison and checks that both values and types, and if both are for example the same number and the same type, the result of the comparison will be 'true'.

Top comments (0)