Skip to content

Instantly share code, notes, and snippets.

@eduardoedson
Created April 23, 2022 23:46
Show Gist options
  • Save eduardoedson/98a7000f522271bbbe0f2ff25ab51182 to your computer and use it in GitHub Desktop.
Save eduardoedson/98a7000f522271bbbe0f2ff25ab51182 to your computer and use it in GitHub Desktop.
JavaScript Closures Sum
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