How to pass a function as a parameter in JavaScript

1 Answer

0 votes
function f() {
    return 'function f()';
}

function test(s, f) {
    const message = f();

    console.log(`${s} ${message}`);
}

test('aaa', f);
test('ccc', f);




/*
run:

"aaa function f()"
"ccc function f()"

*/

 



answered Jan 28, 2022 by avibootz
...