What do you understand by callback hell?

Photo by Max Chen on Unsplash

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