Created
October 24, 2018 23:33
-
-
Save christopheragnus/4ac00c17e8df7b3ddd84b1c79e6a5d2f to your computer and use it in GitHub Desktop.
Example of 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
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