3 ms·
What kind of “unpredictable subtle way” do you think leaving out semicolons can break things? The only way I know is what was mentioned in the article “Semicolo
by roryokane 16y ago
What kind of “unpredictable subtle way” do you think leaving out semicolons can break things? The only way I know is what was mentioned in the article “Semicolons in JavaScript are optional”, where this code is incorrect:
a = b + c
(d + e).print()
. The author of the article says you can fix this by always putting a semicolon before any line-starting parentheses, like
;(d + e).print()
. Are you saying that you expect that rule to be too hard to remember for developers? If not, you should be able to give an example of another case where leaving out semicolons breaks things.
Also, I agree that showing off your understanding of JavaScript parsing is a bad reason to leave out semicolons, but you imply that that is the reason everyone leaves out semicolons, and that is false. As you said, there are aesthetic reasons to do it – but having good aesthetics of code can (slightly) help one understand code more quickly, so it’s not pointless.