1
1
## Automatic Semicolon Insertion
2
2
3
3
Although JavaScript has C style syntax, it does ** not** enforce the use of
4
- semicolons in the source code, it is possible to omit them.
4
+ semicolons in the source code, so it is possible to omit them.
5
5
6
- But JavaScript is not a semicolon-less language, it in fact needs the
7
- semicolons in order to understand the source code. Therefore the JavaScript
6
+ JavaScript is not a semicolon-less language. In fact, it needs the
7
+ semicolons in order to understand the source code. Therefore, the JavaScript
8
8
parser ** automatically** inserts them whenever it encounters a parse
9
9
error due to a missing semicolon.
10
10
@@ -19,7 +19,7 @@ Insertion happens, and the parser tries again.
19
19
test()
20
20
21
21
The automatic insertion of semicolon is considered to be one of ** biggest**
22
- design flaws in the language, as it * can* change the behavior of code.
22
+ design flaws in the language because it * can* change the behavior of code.
23
23
24
24
### How it Works
25
25
@@ -87,7 +87,7 @@ Below is the result of the parser's "guessing" game.
87
87
> which are followed by a new line, while this is not neccessarily the fault of
88
88
> the automatic semicolon insertion, it can still be an unwanted side-effect.
89
89
90
- The parser drastically changed the behavior of the code above, in certain cases
90
+ The parser drastically changed the behavior of the code above. In certain cases,
91
91
it does the ** wrong thing** .
92
92
93
93
### Leading Parenthesis
@@ -106,9 +106,9 @@ the above will yield a `TypeError` stating that `undefined is not a function`.
106
106
107
107
### In Conclusion
108
108
109
- It is highly recommended to ** never** omit semicolons, it is also advocated to
109
+ It is highly recommended to ** never** omit semicolons; it is also advocated to
110
110
keep braces on the same line with their corresponding statements and to never omit
111
111
them for one single-line ` if ` / ` else ` statements. Both of these measures will
112
- not only improve the consistency of the code, they will also prevent the
112
+ not only improve the consistency of the code, but they will also prevent the
113
113
JavaScript parser from changing its behavior.
114
114
0 commit comments