Live data from Hacker News

Semicolons in JavaScript are optional

mislav.uniqpath.com

31–39 of 39 posts

Re: Semicolons in JavaScript are optional

#32
post #4

text 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…

Try my tool: http://toadjaw.com/article?url=http%3A%2F%2Fmislav.uniqpath....

Re: Semicolons in JavaScript are optional

#34

I 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)

Re: Semicolons in JavaScript are optional

#35

FWIW 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

#37
post #35

FWIW 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)

Doh. Yes.

Re: Semicolons in JavaScript are optional

#38
post #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.

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)

Yep, those implementations are crappy, but they are in production and deployed in hundreds of thousands of end-user systems. The author seems to have only been testing PC web browsers, which is not the only place JS is used. This is easy to forget, though.

Re: Semicolons in JavaScript are optional

#39
post #34

I 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)

Why the downvote? A google search didn't turn up anything about a IE-only lack of conformance to the spec regarding semicolons.

If you've seen code that breaks only IE because of a missing semicolon, please share.

Post reply on HN