en.javascript.info/1-js/06-advanced-functions/03-closure/6-closure-sum/solution.md
2019-12-29 00:33:46 +03:00

271 B

For the second parentheses to work, the first ones must return a function.

Like this:

function sum(a) {

  return function(b) {
    return a + b; // takes "a" from the outer lexical environment
  };

}

alert( sum(1)(2) ); // 3
alert( sum(5)(-1) ); // 4