Statement Termination
Disclaimer: this is a subject of near-constant debate. With the belief that some guidelines are better than no guidelines...
DO Use Semicolons¶
-
After a statement:
let x; x = 6; let y = 90; x = x + y; myFunction(); -
When you have two statements on the same line:
for (let i = 0 ; i < 10 ; i++) {} let x; x = 10; let y = x/2; // although for readability...don't do this -
With function expressions:
// This is an assignment statement, it needs a semicolon let myFunction = function(){ }; // This is a multi-line assignment statement, it also needs a semicolon let myOtherFunction = function(num1,num2) { //...implementation code }; -
With do...while loops:
do { // ... something } while (true);
Do NOT Use Semicolons¶
General Rule: With the exception of function expressions and do...while loops, don't follow a } with a semicolon...
-
After a block:
if (true) { } for (;;) { } while (true) { } -
Function statements (be they named or anonymous):
-
Note: these functions are not assignment expressions
function () { } function namedFunc () { }