forked from rohan-paul/Awesome-JavaScript-Interviews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback-hell-examples.js
executable file
·45 lines (38 loc) · 1.18 KB
/
callback-hell-examples.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
39
40
41
42
43
44
45
setTimeout(
changeMaker => {
let list = changeMaker + ", "
setTimeout(
changeMaker => {
list += changeMaker + ", "
setTimeout(
changeMaker => {
list += changeMaker + ", "
setTimeout(
changeMaker => {
list += changeMaker + ", "
setTimeout(
changeMaker => {
list += changeMaker
console.log(list)
},
1,
"Travis Kalanick",
)
},
1,
"MarkZuckerberg",
)
},
1,
"SteveWoz",
)
},
1,
"SteveJobs",
)
},
1,
"BillGates",
)
/* Looking at the above, setTimeout gets a callback function that executes after one millisecond. The last parameter just feeds the callback with data, i.e the argument 'changeMaker' . This is like an Ajax call except the return 'changeMaker' parameter would come from the server.
I am gathering a list of changeMakers through asynchronous code. Each callback gives me a single 'changeMaker' name and I append that to the list. */