Using Callback and creating a Callback Hell situation to understand the drawbacks.
Wed Apr 23 2025 01:13:36 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
function task1(callback) {
setTimeout(() => {
console.log("Task 1 completed");
callback();
}, 1000);
}
function task2(callback) {
setTimeout(() => {
console.log("Task 2 completed");
callback();
}, 1000);
}
function task3(callback) {
setTimeout(() => {
console.log("Task 3 completed");
callback();
}, 1000);
}
function task4(callback) {
setTimeout(() => {
console.log("Task 4 completed");
callback();
}, 1000);
}
// This is where callback hell starts
task1(() => {
task2(() => {
task3(() => {
task4(() => {
console.log("All tasks done!");
});
});
});
});
content_copyCOPY
https://chatgpt.com/share/6806eb90-bdac-800e-8a25-6ffb72f6bc0e
Comments