Skip to content

Instantly share code, notes, and snippets.

Created July 2, 2015 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a5ee00d15085cdffd917 to your computer and use it in GitHub Desktop.
Save anonymous/a5ee00d15085cdffd917 to your computer and use it in GitHub Desktop.
Closures
// given:
var sayHello = function (name) {
var text = 'Hello, ' + name;
return function () {
console.log(text);
};
};
// this does not work:
sayHello('Rex');
//this does:
var helloTodd = sayHello('Rex');
helloTodd(); // returns "Hello, Todd"
// why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment