-
Notifications
You must be signed in to change notification settings - Fork 0
/
promises.js
49 lines (40 loc) · 1.12 KB
/
promises.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
46
47
48
49
// 1 pending
// 2. resolve/reject
// 3. error state
// these above three state are in promises in js
// .... .. .. . .. . .. . ..
// let promise = new Promise((resolve, reject) => {
// setTimeout(() => {
// let age = 21
// if (age > 21) {
// resolve("you are eligible");
// } else {
// reject("You are not eligible")
// }
// }, 4000)
// })
// promise.then(res => console.log(res)).catch(err => console.log(err))
// let promise = new Promise((res, rej) => {
// setTimeout(() => {
// let age = 32;
// if (age > 30) {
// res("you eligible")
// } else {
// rej("not eligible")
// }
// }, 2000);
// })
// console.log("before")
// promise.then(res => console.log(res)).catch(err => console.log(err))
// console.log("after")
let promise = new Promise((res, rej) => {
setTimeout(() => {
let age = 21;
if (age > 30) {
res("you eligible")
} else {
rej("not eligible")
}
}, 2000)
})
promise.then(res => console.log(res)).catch(rej => console.log(rej))