Skip to content

Instantly share code, notes, and snippets.

@andymantell
Last active August 29, 2015 14:15
Show Gist options
  • Save andymantell/d6148c35f6c0d2b4bfdd to your computer and use it in GitHub Desktop.
Save andymantell/d6148c35f6c0d2b4bfdd to your computer and use it in GitHub Desktop.
Multiline var declaration and global leakage
// Multiline var declarations
var foo = 1,
bar = 2,
wibble = 3;
// ... are all too easily turned into this, with a one character change
var foo = 1,
bar = 2; // BOOM: Global scope leakage
wibble = 3;
// Use the multi var pattern to avoid this
var foo = 1;
var bar = 2;
var wibble = 3;
// When the multi var pattern is edited to leak, it's visually very obvious
var foo = 1;
bar = 2;
var wibble = 3;
// Or even better, JSHint your code and it will shout at you if you leak to the global scope!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment