Last active
May 24, 2017 17:03
-
-
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.
This file contains hidden or 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
//@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