A callback is a function that is passed as an argument to another function. This method is used to execute a function(passed as an argument) when the function has finished.
When we use multiple nested callback functions a big problem arises which is known as "Callback Hell". The code rises in the horizontal direction and it becomes less readable and complex. The shape of the code is seen like a pyramid and hence callback hell is also called the “pyramid of doom”.
Let's take an example of different functions from functionA to functionF. All the functions work one after the other and use callback functions such that when functionA execution completes functionB starts execution. And when functionB completes functionC starts execution and so on till functionF until no error occurs.
The code for the above example looks like
It is clear from the above example that the code becomes more difficult to read and increases in the horizontal direction which is a bigger problem.
The callback hell can be resolved using promises which will be discussed in the next blog.