what is a callback function calls back to? code example

Example 1: callback function

function greeting(name) {
  alert('Hello ' + name);
}

function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);

Example 2: callback function

//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()
  }

Example 3: callback function

const ironMan = withGloves(withBoots(withArmor(withHelmet(TonyStark))));

Tags:

Misc Example