Skip to content

Instantly share code, notes, and snippets.

@christopheragnus
Created October 24, 2018 23:33
Show Gist options
  • Save christopheragnus/4ac00c17e8df7b3ddd84b1c79e6a5d2f to your computer and use it in GitHub Desktop.
Save christopheragnus/4ac00c17e8df7b3ddd84b1c79e6a5d2f to your computer and use it in GitHub Desktop.
Example of JS closure
function addSquares(a, b) {
function square(x) {
return x * x;
}
return square(a) + square(b);
}
a = addSquares(2, 3); // returns 13
b = addSquares(3, 4); // returns 25
c = addSquares(4, 5); // returns 41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment