calling a callback function javascript code example
Example 1: create callback function javascript
function add(a, b, callback) {
if (callback && typeof(callback) === "function") {
callback(a + b);
}
}
add(5, 3, function(answer) {
console.log(answer);
});
Example 2: javascript callback function
const message = function() {
console.log("This message is shown after 3 seconds");
}
setTimeout(message, 3000);