javascript use callback function code example
Example 1: callback function js
function greeting(name) {
alert('Hello ' + name);
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
Example 2: callback function js
function myDisplayer(some) { document.getElementById("demo").innerHTML
= some;}function myCalculator(num1, num2, myCallback) {
let sum = num1 + num2;
myCallback(sum);}myCalculator(5, 5, myDisplayer);