r/javascript • • Feb 05 '11

Are Semicolons Necessary in JavaScript?

http://aresemicolonsnecessaryinjavascript.com/
0 Upvotes

66 comments sorted by

View all comments

10

u/9jack9 Feb 05 '11

Yes, it's quite safe, and perfectly valid JS that every browser understands. Closure compiler, yuicompressor, packer, and jsmin all can properly minify it.

I can assure you that packer requires semi-colons. It won't in the next release but you definitely need them if you are using the current online version.

-3

u/sjs Feb 06 '11

The simple solution is to use only minifiers that actually parse JS properly.

3

u/mitsuhiko Feb 06 '11

I welcome you to write a JavaScript parser that parses JS properly.

2

u/sjs Feb 06 '11 edited Feb 06 '11

Why? At least several exist and you can just use one of them. And if you need a minifier use yuicompressor or Closure compiler. They parse real JS not just some subset of it.

2

u/mitsuhiko Feb 06 '11

For understanding why virtual semicolon insertion is retarded.

-1

u/sjs Feb 06 '11

I'm not disputing that it's a misfeature, but it is a part of JS nonetheless. If you minify a subset of JS then you don't minify JS, period.

2

u/mitsuhiko Feb 06 '11

Implicit variable assignments, weird scoping for eval, with and a lot more was also part of JavaScript and is gone in the strict mode. What's your point?

1

u/sjs Feb 06 '11

What's my point? What's your point? You're not even talking about parsing anymore, completely irrelevant.

1

u/mitsuhiko Feb 06 '11

I am talking about parsing. Because it's very damn common to parse programming languages:

  • string extraction for internationalization

  • static analysis

  • implementing an actual interpreter (necessary sometimes)

  • detecting end of statements for feeding an interactive interpreter

  • parsing javascript for automatic comment and function signature extraction (documentation tools)

And a lot more. JavaScript is suppose to be a language that is somewhat easy to implement, easy to sandbox and works the same in different interpreters. Semicolon insertion, the weird rules for the regular expression literal, weird rules for function statements versus function expressions and more are standard features that often work different in different implementations of ECMAScript. You will run on different implementations, for that the language is just too damn common.

So save yourself the trouble and write with semicolons. A lot of tools will not do the extra trouble and implement semicolon insertion. And if they do, chances are they do it wrong and might choke on your code.