Last active
February 2, 2018 10:08
-
-
Save ifkas/11e24284c6884241b09f9a603f0b3cc7 to your computer and use it in GitHub Desktop.
JS Closure
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
// Example with parameter only, no variable in scope and anonymous inner function | |
function orange(color) { | |
return function(brand) { | |
return "The oranges are with " + color + " color, but the computer brand can be " + brand; | |
} | |
} | |
let coloring = orange("orange"); | |
console.log(coloring("apple")); | |
// > The oranges are with orange color, but the computer brand can be apple | |
// Or in some situations we can simplify the above without declaring variable: | |
orange("Relishes")("Red"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment