How do you call nested functions?

function multiplier(factor) {
  return number => number * factor;
}

let twice = multiplier(2);
console.log(twice(5));
// → 10

When did we add an argument in the number parameter to the arrow function ?

@WheySkills When you call that function in console.log(), because you execute multiplier function which returns anonymous function and pass it to variable twice, then you call with parametr 5 in this case, but you can call it with whatever number you want.

1 Like

multiplier(2) returns a function, which is stored in twice, so when you do twice(5) you are passing a value in the number parameter

Logging out twice (without calling it) may also help and give you an idea of what is going on.

function multiplier(factor) {
  return number => number * factor;
}

let twice = multiplier(2);
console.log(twice);
// returns number => number * factor
1 Like