Created
July 2, 2015 23:58
-
-
Save anonymous/a5ee00d15085cdffd917 to your computer and use it in GitHub Desktop.
Closures
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
// 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