-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromise.js
More file actions
55 lines (46 loc) · 1.18 KB
/
promise.js
File metadata and controls
55 lines (46 loc) · 1.18 KB
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
53
54
55
example = () => {
var promise = new Promise(function (resolve, reject) {
resolve(1);
});
promise.then(function (val) {
console.log(val); // 1
return val + 2;
}).then(function (val) {
console.log(val); // 3
});
console.log('\n');
console.log("hello");
}
// example();
example2 = () => {
var promise = new Promise(function (resolve, reject) {
const python = "I'm learning javascript.";
const javascript = "I'm learning javascript.";
if (python === javascript) {
resolve();
} else {
reject();
}
});
promise.then(function () {
console.log('Success, you got a new job.');
}).catch(function () {
console.log('Some error has occured.');
});
}
example2();
example3 = () => {
let completed = false;
new Promise(function (resolve, reject) {
if (completed) {
resolve();
} else {
reject();
}
}).then(function () {
console.log("I've completed learning programming.");
}).catch(function () {
console.log("I haven't completed learning JS programming.");
})
}
example3();