3 ms·
> when would that ever happen legitimately? Never. Aka, on buggy code. Instead of asking when that happens legitimately, why don't you ask why does it evaluat
by epidemian 13y ago
> when would that ever happen legitimately?
Never. Aka, on buggy code.
Instead of asking when that happens legitimately, why don't you ask why does it evaluate to a legitimate value?
> Why would you expect any language to do something that made sense doing that?
Because raising an error in those cases would:
1. Make the language simpler and easier to understand (and to implement). No coercion rules, not guessing what some other developer meant when they wrote `a == 0` (are they asking for numeric equality, or could `a` be a string or a boolean value too?).
2. Make it easier to identify the bug in case it should happen.
Let me ask you, do you also think syntax errors are unnecessary too? Because, why would anyone write a program with invalid syntax? Why would one expect any language to do something that made sense, like not compiling/running the code, in those cases? Wouldn't it be better if, for example, in case a line contains a syntactic error, the interpreter would just discard that like and run the program anyway?
- TheZenPsycho 13y agoYou can't make history something it's not. You might or might not remember visiting the web soon after javascript was released. It involved a lot of broken code, and a lot of error pop ups. Javascript was, historically, a dumb easy scripting language for simple interactive effects on the web. When we're talking about a script that is downloaded from a server, and runs in a browser, that is a much different kind of situation than a programming language usually encounters. It is in the browser maker's interest to be liberal about what it accepts. this is the core reason for the success of html, and the failure of xhtml. as much as the makers of javascript would like to remove certain problematic features, they cannot without breaking old existing content. Now if you want a strict language in the browser that disallows that sort of nonsense, it's easy. Just run JSLINT on your code before deploying it. JSLint considers as an error, pretty much all of your complaints here. If you don't like some aspect of javascript, you can simply not use it. If there's something jslint doesn't catch, I suppose you could always add stuff to jslint. JSLINT is your static compiler. There are solutions to your pain and suffering. you don't have to endure it.