Created
October 6, 2010 04:13
-
-
Save shazow/612814 to your computer and use it in GitHub Desktop.
Examples where lack of semicolons break Javascript code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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