Skip to content

Instantly share code, notes, and snippets.

@shazow
Created October 6, 2010 04:13
Show Gist options
  • Save shazow/612814 to your computer and use it in GitHub Desktop.
Save shazow/612814 to your computer and use it in GitHub Desktop.
Examples where lack of semicolons break Javascript code
// Examples where lack of semicolons break things
// Example 1:
function a() { return "a" }
function b() { return "b" }
var foo = [1,2,3]; // <--- remove this semicolon to break things
-1 == a() || b();
foo // takes value of "b" if there's no semicolon
// Example 2:
function Foo() {};
Foo.prototype.bar = function() {
return 42;
}; // <--- remove this semicolon to break everything
(function() {
// Initialization code wrapped in a function to create scope for locals...
return "hi";
})();
var f = new Foo();
f.bar(); // Takes value of "hi" if above semicolon is removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment