Menu

1 / 4

How to deal with nested callbacks and avoid “callback hell”

We’ve moved to freeCodeCamp.org/news - Medium·Zell Liew·8 months ago
#R5ZAUDC0
Long article (1552 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.