-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_simplePromise.js
34 lines (30 loc) · 1.26 KB
/
05_simplePromise.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
// This show how a promise can either resolve (succeed) or fail (reject) and how to handle the various outcomes.
Promise.resolve("This promise will resolve (succeed)")
.then(function(value) {
console.log("First promise 'then' branch has been called with:" + value);
})
.catch(function(value) {
console.log("First promise 'catch' branch has been called with:" + value);
});
Promise.reject("This promise will reject (fail)")
.then(function(value) {
console.log("Second promise 'then' branch has been called with:" + value);
})
.catch(function(value) {
console.log("Second promise 'catch' branch has been called with:" + value);
});
/*
Uncomment this promise chain (line 23 onward). run the code and check the output.
Change the third promise chain from 'reject' to 'resolve', and run again.
Notice how the 'finally' statement runs in either case
*/
// Promise.reject("This promise will reject")
// .then(function(value) {
// console.log("Third promise 'then' branch has been called with:" + value);
// })
// .catch(function(value) {
// console.log("Third promise 'catch' branch has been called with:" + value);
// })
// .finally(function() { //
// console.log("Third promise 'finally' branch has been called!");
// });