-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path053-Callback-Hell.js
38 lines (33 loc) · 1.04 KB
/
053-Callback-Hell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
author : Jaydatt Patel
Callback hell is a phenomenon where a Callback is called inside another Callback. It is the nesting of multiple Callbacks inside a function. If you look at the design of the code, it seems just like a pyramid. Thus the Callback hell is also referred to as the ‘Pyramid of Doom’.
Callback hell structurally is just a nesting of function calls inside a function. But, it becomes difficult to understand and keep track of the nesting once the size of the nesting is increased.
*/
function print(i) {
console.log("This is call number " + i);
}
function fun(callback) {
setTimeout(() => {
let i = 1;
callback(i);
i++;
setTimeout(() => {
callback(i);
i++;
setTimeout(() => {
callback(i);
i++;
setTimeout(() => {
callback(i);
i++;
setTimeout(() => {
callback(i);
i++;
// .... and so on
}, 800);
}, 700);
}, 500);
}, 300);
}, 100);
}
fun(print);