What the f#$k is strict equality.
Eduardo Henao
Posted on April 10, 2024
Sometimes I see some memes regarding Javascript equality and yeah, some of them are pretty funny, here is my favorite.
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'.
Posted on April 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.