Last active
August 29, 2015 14:15
-
-
Save andymantell/d6148c35f6c0d2b4bfdd to your computer and use it in GitHub Desktop.
Multiline var declaration and global leakage
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
// 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