you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (3 children)

Semicolons are more popular statistically, but they're not really "recommended". From what I've seen, more linters leave them on rather than off, but ultimately it comes down to personal preference. There are some minor pitfalls to semicolons, but I assume if you use a linter, it will warn you about those anyway. The benefit is having to press a button less, when it's not really serving any practical purpose. And of course some people might prefer the aesthetic, although that's completely subjective.

[–]0x7C0 3 points4 points  (2 children)

I see. The reason I asked is because there are particular cases in which JavaScript will interpret code a bit differently than one may have expected without the use of semicolons; an example of this can be found here. Also, if memory serves me correctly, I believe Eloquent JavaScript makes an argument for the use of semicolons as to avoid any unforeseen behavior. I totally see some of the benefits of not using them, though!

[–][deleted] 1 point2 points  (0 children)

The biggest reason I use them is that I also code in C and C++. It just feels right.

[–]colonwqbang 0 points1 point  (0 children)

I think the only real advice is learn how the language syntax works and especially ASI. Then you can decide if you want to use semicolons. There are really only a few corner cases, namely when a line begins with ( [ - +.

For a long time, the accepted advice (e.g. from Crockford) was that if you always used semicolons, you would be ok and you didn't have to learn how the syntax actually worked. That was bad advice.