Callback Hell

noun

say it: “KAWL-bak HEL” /ˈkɔlbæk hɛl/

Code where callbacks sit inside callbacks inside callbacks, each step indented further, until it is hard to read, change or handle errors in.

What is Callback Hell in JavaScript?

Callback Hell — What code looks like when each step that waits takes a callback and the next step goes inside it: the code creeps to the right, and errors have to be handled at every level. Promises and async/await flatten it.

setTimeout(() => {
  console.log('Dough ready');
  setTimeout(() => {
    console.log('Pizza baked');
    setTimeout(() => {
      console.log('Pizza boxed'); // three levels deep already
    }, 100);
  }, 100);
}, 100);

In a sentence

  • “Rewriting the steps with async and await got us out of callback hell: each step is now one line under the last.”
  • “The order code had five timers nested inside each other, a textbook case of callback hell.”

Level: Journeyman · More JavaScript terms at this level

Updated