Skip to main content
Ac
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

The YUI Compressor and dojo shrinksafe should work perfectly fine without semicolons since they're based on a full javascriptJavaScript parser. But Packer and JSMin won't.

The other reason to always use semi-colons at the end of statements is that occasionally you can accidentally combine two statements to create something very different. For example, if you follow the statement with the common technique to create a scope using a closure:

var literal = {
    say: function(msg) { alert(msg); }
}
(function() {
    // ....
})();

The parser might interpret the brackets as a function call, here causing a type error, but in other circumstances it could cause a subtle bug that's tricky to trace. Another interesting mishap is if the next statement starts with a regular expression, the parser might think the first forward slash is a division symbol.

YUI Compressor and dojo shrinksafe should work perfectly fine without semicolons since they're based on a full javascript parser. But Packer and JSMin won't.

The other reason to always use semi-colons at the end of statements is that occasionally you can accidentally combine two statements to create something very different. For example, if you follow the statement with the common technique to create a scope using a closure:

var literal = {
    say: function(msg) { alert(msg); }
}
(function() {
    // ....
})();

The parser might interpret the brackets as a function call, here causing a type error but in other circumstances it could cause a subtle bug that's tricky to trace. Another interesting mishap is if the next statement starts with a regular expression, the parser might think the first forward slash is a division symbol.

The YUI Compressor and dojo shrinksafe should work perfectly fine without semicolons since they're based on a full JavaScript parser. But Packer and JSMin won't.

The other reason to always use semi-colons at the end of statements is that occasionally you can accidentally combine two statements to create something very different. For example, if you follow the statement with the common technique to create a scope using a closure:

var literal = {
    say: function(msg) { alert(msg); }
}
(function() {
    // ....
})();

The parser might interpret the brackets as a function call, here causing a type error, but in other circumstances it could cause a subtle bug that's tricky to trace. Another interesting mishap is if the next statement starts with a regular expression, the parser might think the first forward slash is a division symbol.

Making the answer a little more relevant to the question, correcting a slight mistake - it was a type error, not a syntax error.
Source Link
Daniel James
  • 3.9k
  • 24
  • 30

YUI Compressor and dojo shrinksafe should work perfectly fine without semicolons since they're based on a full javascript parser. But Packer and JSMin won't.

The other reason to always use semi-colons at the end of statements is that occasionally you can accidentally combine two statements to create something very different. For example, if you usefollow the statement with the common technique to emulatecreate a private namespace withscope using a closure:

var literal = {
    say: function(msg) { alert(msg); }
}
(function() {
    // ....
})();

If the previous statement wasn't terminated with a semi-colon, theThe parser might interpret the brackets as a function call, at best creatinghere causing a syntaxtype error and at worst,but in other circumstances it could cause a subtle bug that's tricky to trace. Another interesting mishap is if the next statement starts with a regular expression, the parser might think the first forward slash is a division symbol.

YUI Compressor and dojo shrinksafe should work perfectly fine without semicolons since they're based on a full javascript parser. But Packer and JSMin won't.

The other reason to always use semi-colons at the end of statements is that occasionally you can accidentally combine two statements to create something very different. For example, if you use the common technique to emulate a private namespace with a closure:

(function() {
    // ....
})();

If the previous statement wasn't terminated with a semi-colon, the parser might interpret the brackets as a function call, at best creating a syntax error and at worst, a subtle bug that's tricky to trace. Another interesting mishap is if the next statement starts with a regular expression, the parser might think the first forward slash is a division symbol.

YUI Compressor and dojo shrinksafe should work perfectly fine without semicolons since they're based on a full javascript parser. But Packer and JSMin won't.

The other reason to always use semi-colons at the end of statements is that occasionally you can accidentally combine two statements to create something very different. For example, if you follow the statement with the common technique to create a scope using a closure:

var literal = {
    say: function(msg) { alert(msg); }
}
(function() {
    // ....
})();

The parser might interpret the brackets as a function call, here causing a type error but in other circumstances it could cause a subtle bug that's tricky to trace. Another interesting mishap is if the next statement starts with a regular expression, the parser might think the first forward slash is a division symbol.

Source Link
Daniel James
  • 3.9k
  • 24
  • 30

YUI Compressor and dojo shrinksafe should work perfectly fine without semicolons since they're based on a full javascript parser. But Packer and JSMin won't.

The other reason to always use semi-colons at the end of statements is that occasionally you can accidentally combine two statements to create something very different. For example, if you use the common technique to emulate a private namespace with a closure:

(function() {
    // ....
})();

If the previous statement wasn't terminated with a semi-colon, the parser might interpret the brackets as a function call, at best creating a syntax error and at worst, a subtle bug that's tricky to trace. Another interesting mishap is if the next statement starts with a regular expression, the parser might think the first forward slash is a division symbol.