Last active
May 23, 2016 16:49
-
-
Save wolfieorama/0e227f142ea7ccb00bce023f23cad106 to your computer and use it in GitHub Desktop.
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
function testClosure (){ | |
var x = 4; | |
function closeX(){ | |
return x; // NB: x is not stored anywhere in the innermost function its a global variable | |
} | |
return closeX; | |
} | |
var checkLocalX = testClosure(); | |
checkLocalX(); // this will return 4 even testClosure function has been closed because its local variable has now been bound within checkLocalX | |
// because it has been bound as a closure within closeX | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment