Created
April 23, 2022 23:46
-
-
Save eduardoedson/98a7000f522271bbbe0f2ff25ab51182 to your computer and use it in GitHub Desktop.
JavaScript Closures Sum
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 sum(a) { | |
return function (b) { | |
if(typeof(b) === 'number') | |
return sum(a + b) | |
return a | |
} | |
} | |
console.log(sum(5)()) // 5 | |
console.log(sum(5)(10)()) // 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment