+ 2
Please why isn't the function call correct in the closure example below
5 Answers
+ 1
Hi Sammy
Not sure what you are trying to do, but this may help.
Your first return is causing some problems as it will exit the inner function before the give function will execute
var addTo= function(passed){
var add = function(inner){
//return passed + inner;
var give=function(give){
let tmp=give+2;
console.log("give func"+tmp);
return tmp;
};
console.log("inner func");
return give; //why isn't this returning 8
};
return add;
};
console.log(((addTo(1))(2))(3)); //nested IIFEs
+ 3
Thus may help
https://code.sololearn.com/WqmI440pwdwR/?ref=app
+ 1
After a bit more reading, I think you are after this interview question.
// Lexically nested function definitions defined within enclosing function
function Sum(arg0) {
  function Inner1(arg1) {
    function Inner2(arg2) {
      return arg0 + arg1 + arg2;
    }
    return Inner2;
  }
  return Inner1;
}
console.log(Sum(3)(4)(5));
0
thanks everyone... you've all helped