Automatic Semicolon Insertion:
*
Rules of Automatic Semicolon Insertion
There are three basic rules of semicolon insertion:
LineTerminator.
\}.
Program, then a semicolon is automatically inserted at the end of the input stream.
LineTerminator here]” within the restricted production (and therefore such a token is called a restricted token), and the restricted token is separated from the previous token by at least one LineTerminator, then a semicolon is automatically inserted before the restricted token.
However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement or if that semicolon would become one of the two semicolons in the header of a for statement (see 12.6.3).
Source: ECMA-262, Fifth Edition ECMAScript Specification: