Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

what is callback hell in javascript

function task1(callback) {
  setTimeout(function() {
    console.log("Task 1");
    callback()
  },2000)
}
  
function task2(callback) {
  setTimeout(function() {
    console.log("Task 2");
    callback()
  },2000)
}
 
function task3(callback) {
  setTimeout(function(callback) {
    console.log("Task 3");
    callback()
  },2000)
}
 
function task4() {
  console.log("Task 4");
}
 
function main() {
    task1(function() {
        task2(function() {
            task3(function() {
                task4();
            }) 
        })
    })
}
 
main();
Source by openjavascript.info #
 
PREVIOUS NEXT
Tagged: #callback #hell #javascript
ADD COMMENT
Topic
Name
8+1 =