Callback Functions
A callback is a function passed as an argument to another function, to be invoked later — either after a time delay, after an event, or after an asynchronous operation completes. Callbacks were the original mechanism for handling async operations in JavaScript before promises were introduced.
Simple Callbacks
Higher-order functions like Array.map(), setTimeout(), and event listeners all accept callbacks. These are synchronous or asynchronous depending on the function that calls them.
Error-First Callbacks (Node.js Convention)
Node.js established a convention for async callbacks: the first argument is always an error (or null if no error), and subsequent arguments carry the successful result. This forces callers to handle errors explicitly.
Callback Hell
When callbacks are nested inside callbacks, code can become deeply indented and hard to follow — nicknamed "callback hell" or the "pyramid of doom." Promises and async/await were introduced to solve this readability problem.