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

First commandment of semi-colon-free: any line that starts with [,(,+,- should be prefixed with a semi-colon.

  var x = function() {
    // something
  }
  
  // avoid polluting global scope:
  ;(function() {
    // Some initialization.
  })()

  ;[1,2,3].forEach(...)
In practice those are the only places you'll see (and need) them. It has the extra benefit of disencouraging starting a line with a pre-increment, hacks or weird constructs (not talking of IIFEs of course), and making sure you're never calling a function or accessing properties by accident.


Good advice, and interesting because languages and syntax are interesting to me. But I would never introduce this in my team as a replacement for semicolons at the end of each statement. It seems too random a rule to just follow, hence you'd need to understand the specific problem that it solves. At that point your mental model has become slightly more complex, which doesn't seem worth it.


It's absolutely not random. You only put semi-colons where needed. There is no optional use.

'semicolons at the end of each statement' is much more random. They are unnecessary after function declarations or conditionals, and you might end up forgetting them somewhere that actually matters, just because you're not paying attention. The mental effort for this change is severely overestimated.


But if that really is the only rule needed, then that should be very easy to add to a linter.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: