Last active
October 24, 2018 23:43
-
-
Save christopheragnus/b676140b4f89a37daa58cac6451db078 to your computer and use it in GitHub Desktop.
Example of an Javascript 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
function outside(x) { | |
function inside(y) { | |
return x + y; | |
} | |
return inside; | |
} | |
fn_inside = outside(3); // Think of it like: give me a function that | |
// adds 3 to whatever you give it | |
result = fn_inside(5); // returns 8 | |
result1 = outside(3)(5); // returns 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment