JSFiddle - React, Tailwind, and code Playground
by jonahe
JavaScript
function getHelloFn(name) {
function sayHello() {
console.log("Hello " + name);
}
return sayHello; // return the function, not calling it yet
}
const names = ["Kalle", "Stina", "Bengt", "Emma"];
const helloFunctions = names.map( name => getHelloFn(name) );
helloFunctions.forEach(helloFn => helloFn());
console.log("same as ");
names.forEach( name => getHelloFn(name)() );