Skip to main content

What do you understand by callback hell?

Published 1 min readMarkdown
Part of seriesNode
What do you understand by callback hell?

Callback hell is a term used to describe a situation in JavaScript where the code becomes deeply nested with many levels of callbacks, making it difficult to read and understand. This can happen when writing asynchronous code that relies heavily on callbacks, especially when there are many nested calls.

function step1(callback) {
  setTimeout(function() {
    console.log('Step 1');
    callback();
  }, 1000);
}

function step2(callback) {
  setTimeout(function() {
    console.log('Step 2');
    callback();
  }, 1000);
}

function step3(callback) {
  setTimeout(function() {
    console.log('Step 3');
    callback();
  }, 1000);
}

step1(function() {
  step2(function() {
    step3(function() {
      console.log('Done!');
    });
  });
});

About the author

  • Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference

No comments yet. Be the first to comment.

More from this blog