The `type' attribute is missing.
That is _not_ the example John gave above. You will get a syntax error with
*yours*, because your assumption that `;' is not a(n empty) statement and is
only important as a "parser helper"
Very true: it just not an assumption but exactly how any compliant
engine mechanics work.
if (x)
;
else
x = 3;
and
if (x)
else
x = 3;
are only different that the firs one gives enough info to parser to
build a valid token chain and the second does not so leads to a syntax
error. There is not any mythical EmptyExpression involved in neither
case because it has no relation to the runtime (actual code
execution). From John's comments to his sample:
"The lonely semicolon must be translated into code that jumps over the
'else' part. It can't be thrown away by the parser and forgotten."
- one could wrongly conclude that if-else statement requires at least
one expression in the if-branch or it will error out at runtime. There
is not such requirement for if-else and
if (x) {} else {}
is a perfectly valid - though rather useless - construct.
There is i) the parsing stage when parser tries to build a valid
sequence of valid tokens and gives syntax errors if no way, and ii)
execution stage when the engine is actually trying to execute
requested part of resulted tokens and gives runtime errors if no way.
These are two absolutely different unrelated stages. Semicolons are
used on the first (parsing) stage; there is not any smell of them on
the second (execution) stage.
For further fun of it:
<script>
var code = 'if (true) {3;;}';
alert(eval(code)); // 3
</script>
but the main proof is the memory state of course - if anyone still
feel to be needed a proof of something.