11## Automatic Semicolon Insertion
22
33Although 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.
55
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
88parser ** automatically** inserts them whenever it encounters a parse
99error due to a missing semicolon.
1010
@@ -19,7 +19,7 @@ Insertion happens, and the parser tries again.
1919 test()
2020
2121The 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.
2323
2424### How it Works
2525
@@ -87,7 +87,7 @@ Below is the result of the parser's "guessing" game.
8787> which are followed by a new line, while this is not neccessarily the fault of
8888> the automatic semicolon insertion, it can still be an unwanted side-effect.
8989
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,
9191it does the ** wrong thing** .
9292
9393### Leading Parenthesis
@@ -106,9 +106,9 @@ the above will yield a `TypeError` stating that `undefined is not a function`.
106106
107107### In Conclusion
108108
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
110110keep braces on the same line with their corresponding statements and to never omit
111111them 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
113113JavaScript parser from changing its behavior.
114114
0 commit comments