callbacks Flashcards

1
Q

What is a callback function?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a synchronous callback?

A

A function that is passed to another function and called within that function synchronously, in sequence of normal code execution.

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

processUserInput(greeting);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an asynchronous callback function?

A

Note, however, that callbacks are often used to continue code execution after an asynchronous operation has completed — these are called asynchronous callbacks. A good example is the callback functions executed inside a .then() block chained onto the end of a promise after that promise fulfills or rejects. This structure is used in many modern web APIs, such as fetch().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly