Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There are some caveats. This, for example, would not work as expected:

  foo()
  [1,2,3].forEach(bar)
Automatic semicolon insertion wouldn't work here, because the bracket could be a continuation of the last line. The same goes for parentheses at the beginning of a line.

Source: http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...



Yes, the two cases where I actually think I could run into that are that and var x = i (function() {...})()

where it wil think i( is a function call.


The informal and single easy rule is to prefix lines that begin with punctuation with a semi. In practice only [ and ( crop up, almost nobody begins lines with a prefix increment or decrement. If you use += 1 and -= 1 instead you sidestep that case.


Or, you could just add a semicolon. KISS at work.


Yes, you could just add a semicolon in front of lines that start with punctuation (tiny percentage of all lines) or you could just stick them at the end of every single line...


Yes, you could put them at the end of every statement. Because consistency is a good thing.


@eropple: So you put semicolons after every line? Even after block statements {} ? Why not, if the goal is to be consistent?


You should use the reply button.


It wasn't visible for me on that one comment. I don't know why, I thought it was too deply nested or something, but now I see it. Weird.


The Reply link doesn't show up for a minute or two. I guess it's supposed to force you to think instead of firing off a hasty response. Kind of pointless for one liners but hey...


That's perfectly fine as long as you're honest about why you do it. Most people here are misinformed.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: