Before diving into the central concept i.e. Callback Hell, let's first understand What is Callback and why it is used?
“a callback is a function passed as an argument into another function”
callbacks are superpowerful asynchronous operations to run your code.
Now, Let’s understand the CallBack Hell
Let’s take an example here to understand better about the callback hell. Here is a code of e-commerce. let’s suppose we are working with the API to call the function and there will be functions like createOrder(), proceedToPayment(), and orderSummary().
Now, you have understood this example, where you can see the callback are nested inside one another. this creates a callback hell. Developers face big issues while dealing with the callback hell. Sometimes we can able to understand the code .i.e working behind the code.
Issues with the callback:-
- Callback hell: callback inside another callback and a lot of nested loops become unmaintainable.
- Inversion control: when we lose our program while giving control of our function to another function and we are not sure about that function is ever gonna execute or not.
Thanks for Reading! 😃
Did you find this article valuable?
Support Prateek Singh by becoming a sponsor. Any amount is appreciated!