DEV Community

Discussion on: Semi colons;

Collapse
 
curtisfenner profile image
Curtis Fenner • Edited

JavaScript explicitly has rules for automatically inserting semicolons. Hence, they aren't necessary.

However, the rules aren't very good, in that they are likely to do the wrong thing.

For example, consider the following:

return
    firstLongExpression(thatTakesManyArguments, andPushesMoreToTheNextLine)

It doesn't do what you mean, because the semicolon insertion rules say to put a semicolon here:


return;
firstLongExpression(thatTakesManyArguments, andPushesMoreToTheNextLine);

Your expression's result is lost!

If you set your IDE up to automatically insert semicolons / make your CI tools reject code that would have semicolons inserted automatically, you can avoid these mistakes.