0
function makeAdjectifier(adjective) {
    return function(string) {
        return adjective + "" + string;
    };
}
var coolifier = makeAdjectifier("COOL");
console.log(coolifier("conference")); //outputs "COOLconference"

So, what I see here is coolifier function is being called and conference string is passed as an argument, and coolifier which taking input from makeAdjectifier, & cool is passed as an argument so adjective becomes cool. Now again adjectifier is returning a function which is taking string as a parameter. how conference is available at the inner function so that string becomes equal to conference.

Endenite
  • 382
  • 6
  • 13
Humble Dolt
  • 940
  • 2
  • 16
  • 31

1 Answers1

1

That technique is called "currying" and the most basic explanation would be that by the time you invoked "makeAdjectifier", you created a function that is not only expecting a string but also is aware of the variables that were assigned during its creation.

Here's a cool reference: https://www.sitepoint.com/currying-in-functional-javascript/

Felipe
  • 643
  • 8
  • 13