What are the rules for Javascript's automatic semicolon insertion?
Posted
by T.R.
on Stack Overflow
See other posts from Stack Overflow
or by T.R.
Published on 2010-05-17T02:06:22Z
Indexed on
2010/05/17
2:10 UTC
Read the original article
Hit count: 338
Well, first I should probably ask if this is browser dependent.
I've read that if an invalid token is found, but the section of code is valid until that invalid token, a semicolon is inserted before the token if it is preceded by a line break.
However, the common example cited for bugs caused by semicolon insertion is:
return
_a+b;
which doesn't seem to follow this rule, since _a would be a valid token. On the other hand, breaking up call chains works as expected:
$('#myButton')
.click(function(){alert("Hello!")});
Does anyone have a more in-depth description of the rules?
© Stack Overflow or respective owner