[removed]What is meaning of sum(2)(3) //returns 5;

后端 未结 2 1086
感动是毒
感动是毒 2021-01-07 09:58

Here is code blow to return it\'s value.

function sum(a){
  return function(b){
    return a+b;
  }
}
sum(2)(3);

It returns 5 but

2条回答
  •  借酒劲吻你
    2021-01-07 10:18

    Your 'sum' function returns another function which returns a+b (2 parameters). Both functions together require two parameters: (a) and (b)
    The inner most return, returns a+b. Plugging in your parameters, we get the equation: 2+3.
    Which gives you 5.

    Please let me know if you have any questions or concerns.

提交回复
热议问题