4 ms·
But isn't that part of learning any language? There are plenty of weird edge cases in other languages but we get used to them. Basically this boils down to: "W
by einaregilsson 15y ago
But isn't that part of learning any language? There are plenty of weird edge cases in other languages but we get used to them. Basically this boils down to:
"When you have a single statement, that stretches out over more than one line, but those lines are legal statements on their own, then it won't work like you want it to"
I would guess that the number of statements that stretch out over many lines are a very small part of the overall number of statements for most code.
But it just seems like most developers think that javascript might insert semicolons all over the place. Which it won't, the rules are clear once you learn them.
- einaregilsson 15y agoAhem, maybe not as clear as I thought, since I found a few other edge cases I didn't know of in this excellent article: Best article I've read on the subject: http://inimino.org/~inimino/blog/javascript_semicolons http://inimino.org/~inimino/blog/javascript_semicolons
- felipemnoa 15y agoOr, just add a semicolon and keep it simple. Why risk it? KISS at work.
- einaregilsson 15y agoThere are two possibilities: 1. Prefix lines that start with punctuation, specifically [(-+/ with a ;. Then omit them everywhere else. Lines that start with punctuation are a tiny subset of all lines generally. 2. Postfix every line with a ;, "just in case" I can't see how nr. 1 is harder. And in case 2 you don't actually put ; at the end of every line, you don't put them after {} blocks for example, so it's not like it's somehow easier to remember. "Because we're used to doing it that way" is a reason I guess, but not a great one in my opinion.