Re:JavaScript for People Who Hate JavaScript
by z3t4 on Wednesday August 09, 2017 @03:57PM
(#14972982)
I just tried to get the linter (JShint) to break some valid code, but it didn't. So you can actually rely on the linter to insert the semicolons for you. It would be interesting to find out if there are any cases where the linter will insert the semicolon in the wrong place.
Re:JavaScript for People Who Hate JavaScript
by tedunangst on Wednesday August 09, 2017 @03:58PM
(#14972991)
The browser somehow detects that the missing semicolon wasn't omitted and doesn't add it???
Re:JavaScript for People Who Hate JavaScript
by cerved on Wednesday August 09, 2017 @11:07PM
(#14975989)
No. If it's missing it's inserted obviously. That's why you shouldn't omit it.
Here are the rules for parsing if you're interested
When the program contains a token that is not allowed by the formal grammar, then a semicolon is inserted if (a) there is a line break at that point, or (b) the unexpected token was a closing brace.
When the end of a file is reached, if the program cannot be parsed otherwise, then a semicolon is inserted.
When a "restricted production" is encountered and contains a line terminator in a place where the grammar contains the annotation "[no LineTerminator here]", then a semicolon is inserted.
Use semicolons, lint the code, ????, profit