What do you understand by callback hell in Node.js?

Callback hell is a phenomenon that creates a lot of problems for a JavaScript developer when he tries to execute multiple asynchronous operations one after the other. A function is called an asynchronous function when some external activity must complete before processing a result. It is called asynchronous because there is an unpredictable amount of time before a result becomes available. These functions require a callback function to handle errors and process the result.

Example:

getData(function(a){  

    getMoreData(a, function(b){  

        getMoreData(b, function(c){   

            getMoreData(c, function(d){   

                getMoreData(d, function(e){   

                    ...  

                });  

            });  

        });  

    });  

});

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *