Skip to content

Instantly share code, notes, and snippets.

@alxhub
Last active December 27, 2015 03:29
Show Gist options
  • Save alxhub/7259670 to your computer and use it in GitHub Desktop.
Save alxhub/7259670 to your computer and use it in GitHub Desktop.
// What you have
x = 1;
function foo() {
x = 2;
}
foo();
return x; // Gives 1
// What he wants
x = 1
function foo() {
x = 2;
}
foo();
return x; // Gives 2
// Also what he wants (meaning of "doesn't leak"):
function foo() {
x = 2;
}
foo();
return x; // Error - first definition of 'x' doesn't leak into outer scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment