On Automatic Semicolon Insertion

Before doing JavaScript, I was doing C/C++. There semicolons were required, and you got an error from the compiler when they were missing. I rarely got such errors though because when a semicolon was missing, Emacs would indent badly the following line; bad indentation was always a sign of syntax errors.

So when I moved to JavaScript, semicolons at end of statements made very much sense. The Emacs JS options at that time weren't nearly as good as the C/C++ mode, so sometimes I forgot the semicolon. Although usually the program ran fine, I still went through all sorts of scary bugs because of the automatic semicolon insertion. Oh how I missed that compiler error!

So I got quite religious about using semicolons (also because I was using a simple regexp-based scanner to minify JS, and that was easily screwed by missing semicolons). Nowadays I use Emacs with js2-mode, which contains a full JS parser, and is able to warn about various things during editing, such as missing semicolons.

As a matter of taste, I find code that uses semicolons at the beginning of lines a bit silly:

you can't comment out the spells = line in the same way, because it spans multiple lines. So this argument fades away and let's just say it looks silly.

So as far as my advice goes:

Use an editor with good JS support. If it's just decent, it doesn't qualify. GEdit is decent, but not good enough. Emacs is supremely great.

Configure your editor to warn you about “poor practice”. Again, in Emacs it's possible to do that. For example, my setup warns me if I assign to a variable that's not defined (creating globals is almost always a source of errors), if I forget semicolons, or if I assign in a conditional (where most likely the case is that you want "==" instead of "="). Details on my setup here.

Do insert semicolons and save yourself from the pain of debugging "automatic semicolon insertion".