Recently I was running some of my code through JSLint when I came up with this error. The thing I think is funny about this error though is that it automatically assumes that all == should be ===.
Does that really make any sense? I could see a lot of instances that you would not want to compare type, and I am worried that this could actually cause problems.
The word “Expected” would imply that this should be done EVERY time…..That is what does not make sense to me.
IMO, blindly using
===, without trying to understand how type conversion works doesn’t make much sense.The primary fear about the Equals operator
==is that the comparison rules depending on the types compared can make the operator non-transitive, for example, if:Doesn’t really guarantees that:
For example:
The Strict Equals operator
===is not really necessary when you compare values of the same type, the most common example:We compare the result of the
typeofoperator, which is always a string, with a string literal…Or when you know the type coercion rules, for example, check if something is
nullorundefinedsomething: