Skip to content

Instantly share code, notes, and snippets.

@mamedinfo
Last active August 14, 2019 14:33
Show Gist options
  • Save mamedinfo/c70ce9fb721265777ab493ddde28a304 to your computer and use it in GitHub Desktop.
Save mamedinfo/c70ce9fb721265777ab493ddde28a304 to your computer and use it in GitHub Desktop.
Javascript

Nested functions and closures

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