I just started learning closures in JavaScript and I'm trying to understand a basic problem.
For example, I'm trying to implement the sum method: sum(1)(4)(5)
const sum = (a) => {
return (b) => {
if(typeof b === 'number')
return sum(a+b)
return a;
}
}
When I call: console.log(sum(1)(4)(5)())
it works perfect and return 10. However, if I call console.log(sum(1)(4)(5))
, it returns [Function (anonymous)]
. Why?
Thanks