callback in js

JavaScript
/*
A callback function is a function passed into another function
as an argument, which is then invoked inside the outer function
to complete some kind of routine or action. 
*/
function greeting(name) {
  alert('Hello ' + name);
}

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

processUserInput(greeting);
// The above example is a synchronous callback, as it is executed immediately.// Create a callback in the probs, in this case we call it 'callback'
function newCallback(callback) {
  callback('This can be any value you want to return')
}

// Do something with callback (in this case, we console log it)
function actionAferCallback (callbackData) {
  console.log(callbackData)
}

// Function that asks for a callback from the newCallback function, then parses the value to actionAferCallback
function requestCallback() {
  newCallback(actionAferCallback)
}function greeting(name) {
  alert('Hello ' + name);
}

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

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

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

processUserInput(greeting);const message = function() {  
    console.log("This message is shown after 3 seconds");
}
 
setTimeout(message, 3000);const add = (num1, num2) => num1 + num2;

const result = (num1, num2, cb) => {
  return "result is:" + cb(num1, num2);
}

const res = result(12, 13, add);
Source

Also in JavaScript: