Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iam-peekay
Last active April 27, 2016 22:58
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/d3e0cc91c8888c043df948caf5b348a8 to your computer and use it in GitHub Desktop.
Save iam-peekay/d3e0cc91c8888c043df948caf5b348a8 to your computer and use it in GitHub Desktop.
function sayHello() {
var say = function() { console.log(hello); }
// Local variable that ends up within the closure
var hello = 'Hello, world!';
return say;
}
var sayHelloClosure = sayHello();
sayHelloClosure(); // ‘Hello, world!’
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment