Skip to content

Instantly share code, notes, and snippets.

@knarf-se
Forked from jbgo/semicolons-matter.md
Created June 17, 2011 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knarf-se/1031626 to your computer and use it in GitHub Desktop.
Save knarf-se/1031626 to your computer and use it in GitHub Desktop.
When using semicolons in JavaScript matters
// This fails in firefox, chrome, and maybe others.
// Add a semicolon after foo() and to eliminate the error.
function foo() { /* code goes here */ }
foo() // no semi-colon here
(function() { /* anonymouse function */ })() // bork!
//You can also write the closure like this instead of putting a semicolon after foo:
//!function() { /* anonymouse function */ }() // bork!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment