JavaScriptTechProgrammingProductivityTechnology How to deal with nested callbacks and avoid “callback hell”
Zell Liew
6 min readMay 23, 2019
--
Press enter or click to view image in full size Photo by Jefferson Santos on Unsplash
JavaScript is a strange language. Once in a while, you have to deal with a callback that’s in another callback that’s in yet another callback.
People affectionately call this pattern the callback hell .
It kinda looks like this:
firstFunction(args, function() {
secondFunction(args, function() {
thirdFunction(args, function() {
// And so on…
});
});
});
This is JavaScript for you. It’s mind-boggling to see nested callbacks, but I don’t think it’s a “hell”. The “hell” can be manageable if you know what to do with it.
On callbacks
I assume you know what callbacks are if you’re reading this article. If you don’t, please read this article for an introduction to callbacks before continuing.…