6 ms·
The most common mistake I see when people talk about JS quirks is to assume that this kind of feature is always about fault tolerance rather than convenience.
by mistercow 9y ago
The most common mistake I see when people talk about JS quirks is to assume that this kind of feature is always about fault tolerance rather than convenience.
For example, many languages treat conditions as "if nonzero". From a certain perspective, you could argue that
if (i--) {
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.
- marcosdumay 9y agoHonestly, 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.