function greeting(name) {
alert('Hello ' + name);
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
// A function which accepts another function as an argument
// (and will automatically invoke that function when it completes - note that there is no explicit call to callbackFunction)
funct printANumber(int number, funct callbackFunction) {
printout("The number you provided is: " + number);
}
// a function which we will use in a driver function as a callback function
funct printFinishMessage() {
printout("I have finished printing numbers.");
}
// Driver method
funct event() {
printANumber(6, printFinishMessage);
}
//Callback functions - are functions that are called AFTER something happened
const foo = (number, callbackFunction) => {
//first
console.log(number)
//second - runs AFTER console.log() happened
callbackFunction()
}
function startWith(message, callback){
console.log("Clearly written messages is: " + message);
//check if the callback variable is a function..
if(typeof callback == "function"){
callback(); //execute function if function is truly a function.
}
}
//finally execute function at the end
startWith("This Messsage", function mySpecialCallback(){
console.log("Message from callback function");
})
function greeting(name) {
alert(`Hello, ${name}`);
}
function processUserInput(callback) {
const name = prompt("Please enter your name.");
callback(name);
}
processUserInput(greeting);