call back function js 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: javascript callback
function newCallback(callback) {
callback('This can be any value you want to return')
}
function actionAferCallback (callbackData) {
console.log(callbackData)
}
function requestCallback() {
newCallback(actionAferCallback)
}
Example 3: callback function
const foo = (number, callbackFunction) => {
console.log(number)
callbackFunction()
}
Example 4: js callback function
const add = (num1, num2) => num1 + num2;
const result = (num1, num2, cb) => {
return "result is:" + cb(num1, num2);
}
const res = result(12, 13, add);