-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.js
More file actions
49 lines (34 loc) · 833 Bytes
/
callback.js
File metadata and controls
49 lines (34 loc) · 833 Bytes
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
46
47
48
//syncronour programming is executed line by line;
console.log("1");
console.log("2");
setTimeout(()=>{
console.log("this will take time");//asyncronous fn;
},7000);
console.log("3");
console.log("4");
//callback fn are the fn that are transferred to other fn as an argment;
function sum(a,b){
console.log(a+b);
}
function call(a,b,sum2){
sum2(a,b);
}
call(5,6,sum);//parentheses are not written
//callback hell-. nested calback problem
function prob(dataid,next){
setTimeout(()=>{
console.log(dataid);
if(next){
next();
}
},2000);
}
//prob(1);
//prob(2);
//prob(3);these three will be printed all together after 6s but we wanted one by one;
//callback hell---pyramid structure,,difficult to understand;
prob(1,()=>{
prob(2,()=>{
prob(3);
});
})