A callback function is a function passed into another function as an argument, which is then invoked inside the outer function.
1Functions as Data
In JavaScript, functions are 'First-Class Citizens'. This means they can be assigned to variables, returned from other functions, and most importantly, passed as arguments. A callback is simply a function that is executed after another function has finished executing—hence the name 'call back'. This is the primitive way JavaScript handles asynchronous operations before Promises were introduced.
2The Pyramid of Doom
While powerful, callbacks have a major downside: readability. When you have multiple asynchronous operations that depend on each other, you end up nesting them. This creates a deeply indented structure known as 'Callback Hell' or the 'Pyramid of Doom'. This makes the code extremely difficult to debug and maintain, which is why modern JavaScript evolved to use Promises and Async/Await.
