Callbacks
Callbacks are functions passed as arguments to other functions and invoked at a later time, typically to complete a task or respond to an event. They enable decoupling of the operation from the code that initiates it, making it possible to customize behavior without modifying the caller. Callbacks are a core mechanism in many programming languages and are implemented as function values or references to executable code.
In practice, callbacks are used in synchronous contexts (for example, when an array method applies a function
A frequent design in asynchronous environments is the error-first callback, common in Node.js, where the first
Potential pitfalls include accidental retention of objects via closures, inadvertent multiple invocations, and difficulties canceling pending
See also: function pointers, delegates, promises, futures, asynchronous programming, event-driven programming, continuation-passing style.