Re:JavaScript: The Curious Case of null >= 0
by marcosdumay on Saturday September 09, 2017 @02:41PM
(#15208515)
Honestly, I like implicit coercion of empty stuff into false. Yes, I do agree it makes the code more legible.
That said, objectively it doesn't gain that much. It may be that the cost of having any kind of implicit coercion is bigger than such gain. Implicit numeric coercion is another topic to think about, it is also hard to be sure if it is a net gain.
For example, many languages treat conditions as "if nonzero". From a certain perspective, you could argue that
is "clearly faulty code".From another perspective, you would say it's a shorthand whose meaning is obvious to anyone familiar with the rules of the language.
In my view, JavaScript's sin is that its rules are complicated, and it's difficult to statically analyze, so tools intended to guard against its pitfalls can only do so much.
Whether or not the complicated rules are about faulty code is pretty irrelevant. ASI is an error correction mechanism, but its pitfalls are easy to detect, so in modern environments it doesn't matter. The behavior of comparison operators seems to me like more of a convenience feature, but it's still a problem; the rules are easy to forget, and only a very draconian linter rule can protect you.