Question for the js return.What does?

Hi all,I understand that return returns a value,but you can learn more about this situation,please

why 2 times return f?and again, this is for the circuit?

anyway I can at least briefly explain,thank you
function sum(a) {

 var currentSum = a;

 function f(b) {
 currentSum += b;
 return f;

 f.toString = function() {
 return currentSum;

 return f;

alert( sum(1)(2) ); // 3
alert( sum(5)(-1)(2) ); // 6
alert( sum(6)(-1)(-2)(-3) ); // 0
alert( sum(0)(1)(2)(3)(4)(5) ); // 15
June 8th 19 at 16:36
1 answer
June 8th 19 at 16:38
as already given the answer above return is made for that would call the function infinite number of times.
that is the first time we call the functionsum() it returns us the functionf which in turn can be caused by or output the result if will no longer be used with artificially added the method f.toString()If a function f will be invoked when execution reaches to the currentSum += b; it will not find in their lexical environment currentSum and via[[Scope]] will look for the above that is in functions of sum, they will find this value and uses it. After that will return itself in order for the user to be able to use again the function f

Find more questions by tags JavaScript