Sychronous

A synchronous callback is executed during the execution of the higher order function.
These sychronous callbacks will block the execution of the higher order function.
The higher order function will not finish executing until the callback function has executed


A lot of the built-in JavaScript types use sychronous callbacks, for example
array.forEach(callback)
array.find(callback)
array.filter(callback)
array.reduce(callback, init)


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

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

processUserInput(greeting);

function ask(question, yes, no) { 
  if (confirm(question)) yes()
  else no();
}

ask(
  "Do you agree?",
  function() { alert("You agreed."); },
  function() { alert("You canceled the execution."); }
);



© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext