Before Promises, asynchronous JavaScript was handled with callbacks — functions passed as arguments to be called when an async operation completed. Callbacks work but have a critical weakness: nesting. What is a Callback? A callback is simply a function passed to another function: setTimeout(function() { ... }, 1000). The passed function is "called back" when the timer fires. This pattern is used for events, HTTP requests, file reads, and timers. Callback Hell Callback Hell (also called "Pyramid of Doom") occurs when callbacks are nested inside each other to handle sequential async operations. Imagine: get user → get their posts → get comments on each post → get each commenter's profile. Each step nests deeper, creating code that is impossible to read, maintain, or debug. Problems with…
Key Takeaways
Callbacks = functions passed to run after async operations.
Callback hell = deeply nested callbacks for sequential async steps.
Problems: unreadable, error-prone, hard to maintain.
Promises and async/await solve callback hell.
Callbacks are still valid for events and simple async tasks.