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'.
Top comments (0)