Skip to main content

Command Palette

Search for a command to run...

What do you understand by callback hell?

Updated
1 min read
What do you understand by callback hell?
R

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

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!');
    });
  });
});

More from this blog

R

Raja Muhammad Asher - Senior Software Engineer - Full Stack Developer

157 posts

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