What is the difference between returning a callback and just calling a callback?

Technology CommunityCategory: Node.jsWhat is the difference between returning a callback and just calling a callback?
VietMX Staff asked 4 years ago
return callback();
//some more lines of code; -  won't be executed

callback();
//some more lines of code; - will be executed

Of course returning will help the context calling async function get the value returned by callback.

function do2(callback) {
    log.trace('Execute function: do2');
    return callback('do2 callback param');
}

var do2Result = do2((param) => {
    log.trace(`print ${param}`);
    return `return from callback(${param})`; // we could use that return
});

log.trace(`print ${do2Result}`);

Output:

C:\Work\Node>node --use-strict main.js
[0] Execute function: do2
[0] print do2 callback param
[0] print return from callback(do2 callback param)