Semicolons in JavaScript are optional
11–20 of 39 posts
Re: Semicolons in JavaScript are optional
#12Use semicolons. Always. It's looks cleaner, and you won't come up against stupid errors like return { foo: 7 } From the article - When you're done trying to wrap your brain around why would anyone in their right mind want to write a return statement on a new line Well, if they love having { on newlines, then it's pretty obvious: function foo() { return { bar: 8 } } From the article - That's 24 bytes right there. Stam…
I don't think semicolons help your example. return { foo: 7 }; still returns undefined.
I was really explaining why rookies will make mistakes with js. The simplest way to prevent those types of errors is to always use ; and to use { on the same line style.
Re: Semicolons in JavaScript are optional
#13Earlier quoted context omitted.
I don't think semicolons help your example. return { foo: 7 }; still returns undefined.
And that's one of the reasons (IMHO) that bracketing style sucks. I was really explaining why rookies will make mistakes with js. The simplest way to prevent those types of errors is to always use ; and to use { on the same line style.
Re: Semicolons in JavaScript are optional
#14Re: Semicolons in JavaScript are optional
#15Earlier quoted context omitted.
The original argument is not about the minifier, but about semicolons. By the way, why would your better minifier introduce a semicolon here ? This is obviously a useless character in this example. Also, I don't understand how adding a semicolon could help against the "stupid error" you cite. Could anyone please explain ?
I don't actually remember what closure advanced mode does. It's quite possible it does remove ";" in some instances. But really, you either need a newline or a ";" to mark the end of a statement, so the question is fairly moot - it's gonna be 1 byte either way. If you always put semicolons to mark the end of a statement, then seeing a statement without one would be like seeing a megablocks brick in your lego box - gl…
I am certainly not against coding practices or readability. With (Q)BASIC, you could also add semicolons and have multiple statements per line, but who did ? It seems that it is the same with Javascript, semicolons are separators between statements, as well as newlines : why write both ? just to be sure they are well separated ?
Re: Semicolons in JavaScript are optional
#16Re: Semicolons in JavaScript are optional
#17 I write semicolon-less code and,
in my experience, there isn't a
JavaScript interpreter that can't
handle it.
Come visit me at work and I'll show you a few JS implementations on various set-top-boxes that will freak out if you don't use semicolons.Re: Semicolons in JavaScript are optional
#18What's wrong in using semicolons?
Re: Semicolons in JavaScript are optional
#19Re: Semicolons in JavaScript are optional
#20 for(i=10;i--) { /* do stuff */ }
So maybe that's an example of a JS implementation where it differs on optional semicolons.