Skip to content

Instantly share code, notes, and snippets.

@christopheragnus
Last active October 24, 2018 23:43
Show Gist options
  • Save christopheragnus/b676140b4f89a37daa58cac6451db078 to your computer and use it in GitHub Desktop.
Save christopheragnus/b676140b4f89a37daa58cac6451db078 to your computer and use it in GitHub Desktop.
Example of an Javascript closure
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