4 ms·
I would think they didn’t explain how it makes JS better because they were on the defensive from people who said leaving semicolons out will break code. They ar
by roryokane 16y ago
I would think they didn’t explain how it makes JS better because they were on the defensive from people who said leaving semicolons out will break code. They are saying “stop forbidding me from coding in the style I want, my style works just fine”. They are just trying to defend their style, not convert people to it.
However, that’s not to say there is no reason to omit semicolons. I personally leave out semicolons as an extension of the DRY principle – if you are putting a line break after a statement anyway, then you might as well leave off the semicolon. It’s one less character to delete if you combine two adjacent lines into one. Also, if you already think of line breaks and statement ends going together, then semicolons are just noise that you have to make an effort to ignore – the effort required may be small, but there’s little reason not to avoid that effort.
The only problem with omitting semicolons in JavaScript is this case mentioned in “Semicolons in JavaScript are optional”:
a = b + c
(d + e).print()
The author recommends avoiding the error in that by changing the last line to
;(d + e).print()
. If the extra effort of adding a semicolon before all line-starting parentheses costs more effort than you would save by getting the two advantages I described above, then maybe adding semicolons everywhere is right for you. You might have to experiment with coding in both styles to be able to accurately quantify how much those two advantages and one disadvantage would affect you.