JavaScript Callback after calling function

There’s no special syntax for callbacks, just pass the callback function and call it inside your function.

function a(message, cb) {
    console.log(message); // log to the console of recent Browsers
    cb();
}

a("Hi.", function() {
    console.log("After hi...");
});

Output:

Hi.
After hi...

Leave a Comment