Skip to content

Instantly share code, notes, and snippets.

@iam-peekay
Last active April 28, 2016 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iam-peekay/79cc7a97faf67595d5871819a9747269 to your computer and use it in GitHub Desktop.
Save iam-peekay/79cc7a97faf67595d5871819a9747269 to your computer and use it in GitHub Desktop.
var x = 10;
function foo(a) {
var b = 20;
function bar(c) {
var d = 30;
return boop(x + a + b + c + d);
}
function boop(e) {
return e * -1;
}
return bar;
}
var moar = foo(5); // Closure
/*
The function below executes the function bar which was returned
when we executed the function foo in the line above. The function bar
invokes boop, at which point bar gets suspended and boop gets push
onto the top of the call stack (see the screenshot below)
*/
moar(15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment