Simple rule of thumb for semicolon-less JavaScript
A very easy rule of thumb where semicolons are necessary and allows you not to add semicolons at the end of all statements:
- In for loops:
for(var i = 0; i < 10; i++){}
- In a body-less loop:
while(i === 0);
- If a line starts with any of these characters:
(
example;(function(){})()
[
+
-
You anyway have to add these semicolons because when your files will get concatenated/minified these statements may be right after a library that doesn’t use semicolons.
Never break lines for
There are only few cases where line-breaking does not concatenate statements (applies to both semicolon-everything and semicolon-less approach):
return
break
continue
throw