The code you posted is a Self-executing Anonymous Function, not a Closure. In fact there are no closures in your code at all because no variables' scopes cross function boundaries.
If you want to return a value from an SEAF, just add a return
statement:
const message = (function() {
function hello(name, age) {
return name + ", who is " + age + " years old, says hi!";
}
const result = hello('John', 33);
console.log( result );
return result;
}();
If you want to export the hello
function through the SEAF as a new function without any parameters (because the parameters are captured inside the returned lambda i.e. an example of Partial Application, then do this:
const hello = (function() {
function hello(name, age) {
return name + ", who is " + age + " years old, says hi!";
}
return () => hello('John', 33);
}());
console.log( hello() ); // will print "John, who is 33 years old, says hi!" to the console.