callback

A function you pass to other code so it can call you back later, for example when an event happens or a timer fires.

In more detail

Event listeners, timers and many older asynchronous APIs take callbacks. The code that receives the callback decides when, and how often, to call it.

Examples

In the browser: addEventListener, MutationObserver, setTimeout and promise then() all take callbacks, and the event loop decides when each runs.
Java: callbacks are usually lambdas or method references, such as .filter(User::active).
In React, parents pass callbacks such as onToggle as props so children can report events upward.

Related terms

Taught in

References

Certification courses