How to avoid callback hell – Async vs Promises
There are the various ways of writing asynchronous code and if there is any better way of writing such code, we should go for it. I have attached the 4 different ways of writing the same asynchronous code. It’s a dummy code which basically invokes 3 ajax calls where 2nd call is dependent on first and third one is dependent on second.
1.Callback Hell – Here all the callback logic goes into the unnamed anonymous success/error callbacks. It grows in a nested way and can become almost impossible to debug.