While it’s clear how using the === operator for e.g. numbers is useful (0, null and undefined all being falsy values, which can lead to confusion), I’m not sure if there are benefits to using === for string comparisons.
Some of my team mates use this operator for all comparisons, but does it really make sense? Is there at least some minor performance impact?
If you know the types are the same, then there’s no difference in the algorithm between
==and===.That said, when I see
==, I assume that I’m using it for its type coercion, which makes me stop and analyze the code.When I see
===I know that there’s no coercion intended, so I don’t need to give it a second thought.In other words, I only use
==if I intend for there to be some sort of type coercion.