How to pass a function as a parameter in Node.js

1 Answer

0 votes
function f() {
    return 'function f()';
}
 
function test(s, f) {
    const message = f();
 
    console.log(`${s} ${message}`);
}
 
test('zzz', f);
test('ppp', f);
 
 
 

 
/*
run:
 
zzz function f()
ppp function f()
 
*/

 



answered Jan 29, 2022 by avibootz
...