JavaScript Missing Semicolon


For maybe the first time ever, I produced a bug in my JavaScript code that was the result of a parsing ambiguity created by omitting the semicolon at the end of a statement:

    alert("ah ha ha ha");

And so Ye Olde Firebug complained that console.log(“blargh”) was not actually a function. The misunderstanding stemmed from the fact that the first character on the second line is an opening parenthesis, which apparently causes the parser to assume the return value of the previous expression is a function that I intend to call, even though it’s on a separate line.

The lesson here, kids, is that you should always include the semicolons in your JavaScript. If you don’t, you might end up like me: having to waste an average of ten minutes every eight years or so picking parsing mistakes out of my sloppy, lazy code. DON’T LET THIS BE YOU!


There's some javascript trying to load some comments, and if you're reading this, it's probably not working.