JavaScript/Automatic semicolon insertion

Automatic Semicolon Insertion (ASI)

In languages of the C-family, the semicolon denotes the end of a statement. Unlike other C-like languages, JavaScript doesn't enforce that. Instead, the semicolon is optional, and the interpreter adds missing semicolons - mostly at the end of a line - to terminate statements. Doing so, it takes complex rules into account. This may conflict with the intended purpose.

If you write your code without semicolons at the end of statements you must take care of problematic situations. Here are some rules-of-thumb to avoid problems. But there are many more rules.

Examples
 * 1) The expression after one of the keywords ,  , or   must be on the same line as the keyword itself.
 * 2) The label identifier after   or   must be on the same line as the keyword.
 * 3) If a line starts with one of ,  ,  ,  ,  , or  , end the previous line with a semicolon.

In the first case, the programmer intended 2*a + 1 to be returned; instead, the code returned. Similarly, in the second case, the programmer intended to return the lines enclosed by the braces, but the code returned. Due to this oddity in JavaScript, it is considered a best practice never to have lines break within a statement and never have the opening brace on a separate line.