Skip to content

Instantly share code, notes, and snippets.

@daytonn
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save daytonn/58b3b16151ed175d90ea to your computer and use it in GitHub Desktop.

Select an option

Save daytonn/58b3b16151ed175d90ea to your computer and use it in GitHub Desktop.
CWCPOOJS - leaking globals
var foo = 5;
var bar = 10;
function logFoo() {
foo = 15;
var bar = 20;
console.log("logFoo scope")
console.log(foo, bar);
}
logFoo(); // 15, 20
console.log("global scope (window)")
console.log(foo, bar); // 15, 10
console.log(window.foo, window.bar); // 15, 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment