call back function in javascript examples
Example 1: call back function in javascript
function greeting(name) {
alert('Hello ' + name);
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
Example 2: what are callback functions
funct printANumber(int number, funct callbackFunction) {
printout("The number you provided is: " + number);
}
funct printFinishMessage() {
printout("I have finished printing numbers.");
}
funct event() {
printANumber(6, printFinishMessage);
}
Example 3: 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)
}