-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassync.ts
52 lines (43 loc) · 1.05 KB
/
assync.ts
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
49
50
51
52
// // arrow function
// let sum (num1:number,num2:number,num3:number)=>{
// console.log(num1+num2+num3);
// };
// // call back function
// function makeBreakfast(fn:() => void) {
// console.log("making breakfast");
// fn()
// }
// function eatbreakfast() {
// console.log("eat your breakfast");
// }
// makeBreakfast(eatbreakfast)
// // synchronous programming
// console.log("second");
// for (let i = 0; i<100;i++){
// console.log("first");
// }
// console.log("third");
// // asynchronous programming
// console.log("first");
// setTimeout(() => {
// console.log("second");
// }, 2000000);
// console.log("third");
// promise
let party = new Promise((resolve,reject)=>{
setTimeout(() => {
let mood="naughty"
if (mood==="fresh") {
resolve("Chalo");
}
else{
reject("phir kabhi")
}
}, 1000);
})
party.then((data)=>{
console.log(data);
})
.catch((err)=>{
console.log(err);
})