Semicolons in JavaScript are optional
31–39 of 39 posts
Re: Semicolons in JavaScript are optional
#32text on there made my eyes hurt. the basic message seems to be "don't do what everyone else is doing just because everyone else does it". Which is great in your bedroom, but in a team with lots of eyes on your code the most efficient way is to use the same style, with that style being one that is easy to read and that avoids potential misunderstandings and bugs. I can't imagine any situation in the sphere of developm…
Re: Semicolons in JavaScript are optional
#33Use semicolons or your shit wont work in IE... That's why semicolons in javascript AREN'T optional.
Re: Semicolons in JavaScript are optional
#34I use semicolons, and a linter to let me know when I miss them, because IE pukes all over itself if I don't. Same with trailing commas, IE HATES those. Article ignores reality.
Re: Semicolons in JavaScript are optional
#35FWIW If you're using JavaScript in PhotoShop the following produces an error because there's no semicolon after the second statement: for(i=10;i--) { /* do stuff */ } So maybe that's an example of a JS implementation where it differs on optional semicolons.
http://www.ecma-international.org/publications/files/ECMA-ST...
Section 7.9.2 (page 37)
Re: Semicolons in JavaScript are optional
#36Re: Semicolons in JavaScript are optional
#37FWIW If you're using JavaScript in PhotoShop the following produces an error because there's no semicolon after the second statement: for(i=10;i--) { /* do stuff */ } So maybe that's an example of a JS implementation where it differs on optional semicolons.
That doesn't work in any javascript interpreter. Semi-colons aren't optional inside the parenthesis of a for statement, according to the spec. http://www.ecma-international.org/publications/files/ECMA-ST... Section 7.9.2 (page 37)
Re: Semicolons in JavaScript are optional
#38I 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.
So in essence, the problem is still to be blamed on those specific JS implementations. Optional means optional, at which point making an implementation that demands the absence of semicolons is as bad as one explicitly requiring them, as both are breaking the set rule: optional . (personally, I'm for the mandatory semicolon, to avoid mistakes)
Re: Semicolons in JavaScript are optional
#39I use semicolons, and a linter to let me know when I miss them, because IE pukes all over itself if I don't. Same with trailing commas, IE HATES those. Article ignores reality.
I'd like to see an example of IE breaking without semi-colons. I've never seen that happen before. (I have seen the issue w/ commas though)
If you've seen code that breaks only IE because of a missing semicolon, please share.