Last active
November 29, 2019 16:55
-
-
Save rajmayank/e6efb03512f8d6030a6f6a4bd116f1b6 to your computer and use it in GitHub Desktop.
JavaScript Closures - 2
This file contains 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 customGreet(greetingPrefix) { | |
var customGreetingPrefix = greetingPrefix; // For simplicity we store it explicitly in a local variable | |
function printGreet(name) { | |
console.log(customGreetingPrefix + ' ' + name + '.'); | |
} | |
return printGreet; | |
} | |
greetWithHey = customGreet('Hey'); | |
greetWithHello = customGreet('Hello'); | |
greetWithHey('Tom'); | |
greetWithHello('Jerry'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment