Semicolons are not optional. They are inserted for you as a convenience when the parser can figure out what you meant.
This situation wasn't a big deal in the early days. But the patterns of coding that have emerged to deal with Javascript's scoping problems have brought this from a curiosity to something profoundly crazy.
Using an operator (i.e. !) to fool the parser is hilarious but really not OK.
Writing code is an exercise in communication. You are communicating with other programmers (including your future self) and the parser. The zero semicolon style espoused by @fat is problematic for both other programmers and the parser. Perhaps one day @fat will win and his style of communication will be sufficiently accepted to be valid but this is not that day.
The relevant section of the ECMAScript spec is included for your convenience:
7.9 Automatic Semicolon Insertion
Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in certain situations. These situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations.
Semicolons are not optional. They are inserted for you as a convenience when the parser can figure out what you meant.
This situation wasn't a big deal in the early days. But the patterns of coding that have emerged to deal with Javascript's scoping problems have brought this from a curiosity to something profoundly crazy.
Using an operator (i.e. !) to fool the parser is hilarious but really not OK.
Writing code is an exercise in communication. You are communicating with other programmers (including your future self) and the parser. The zero semicolon style espoused by @fat is problematic for both other programmers and the parser. Perhaps one day @fat will win and his style of communication will be sufficiently accepted to be valid but this is not that day.
The relevant section of the ECMAScript spec is included for your convenience:
7.9 Automatic Semicolon Insertion Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in certain situations. These situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations.
http://www.ecma-international.org/publications/standards/Ecm...