Could any one explain how this function alert, when more no of brackets of parameters are passed. I could not able to understand it clearly.
function sum(a) {
The sum
and f
functions always return the f
function, you can invoke it infinite times without getting a result other than the function.
The value is only returned by the overwritten toString
method of f
(which actually returns a number):
console.log( sum(1)(2) ) // Function(){}
console.log( sum(1)(2).toString() ) // 3
The alert
function implicitly invokes the toString
method when it casts its arguments to strings.