Skip to content

Instantly share code, notes, and snippets.

@dineshvgp
Last active May 24, 2017 17:03
Show Gist options
  • Save dineshvgp/dcb077bfed63813c105142df885b3831 to your computer and use it in GitHub Desktop.
Save dineshvgp/dcb077bfed63813c105142df885b3831 to your computer and use it in GitHub Desktop.
An inner function always has access to the variables and params of its outer function, even after the outer function has been returned.
//@see: http://davidshariff.com/blog/javascript-scope-chain-and-closures/
function foo() {
var a = 'private variable';
return function bar() {
alert(a);
}
}
var callAlert = foo();
callAlert(); // private variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment