While trying to debug some faulty piece of JavaScript, I found a line that looks like an obvious mistake in a source file:
false++;
What I don't undestand is why this statement behaves differently in all browsers.
Is it by design that different browsers are allowed to handle the same broken JavaScript in different ways?
I know what the error is and how to fix it, but shouldn't at least the error type be mandated by the spec?
Chrome appears to be up to date.
ReferenceError
is thrown when trying to assign to a primary expression that is a literal (such as false
) not an identifier.SyntaxError
s) of unspecified type is thrown for assignments "on any value for which an early determination can be made that the value is not a Reference", though if it would happen a ReferenceError
would be thrown so one might argue that the early error should be of that type as well.While the error handling in Firefox may be excused by the ES5 or ES3 wording, the behaviour Internet Explorer throwing a runtime SyntaxError
does not match any of these. However, Microsoft plans to fix this in Chakra. For further discussion, see https://github.com/tc39/ecma262/issues/257 and https://github.com/tc39/ecma262/issues/691.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With