function greet(name) {
function displayName() {
console.log('Hi' + ' ' + name);
}
// returning a function
return displayName;
}
const g1 = greet('John');
console.log(g1); // returns the function definition
g1(); // calling the function
// Javascript double parentheses
// first function call result in a function that is called
function a() {
return (name = 'b') => console.log(`I'm function ${name} produced by a()`);
}
a()();
a()('b2');
// result :
// I'm function b produced by a()
// I'm function b2 produced by a()