Last active
February 26, 2024 07:31
-
-
Save homostellaris/35280ae5382fe8987682fe476b19a04b to your computer and use it in GitHub Desktop.
Promise execution order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hi = Promise.resolve('hi') | |
| console.log(1, hi) // 1 Promise { 'hi' } | |
| const hiAgain = hi.then(hi => { | |
| console.log(4, hi) // hi | |
| return hi | |
| }) | |
| hiAgain.then(hi => { // No point in this additional `then` call | |
| console.log(5, hi) // hi | |
| return hi | |
| }) | |
| console.log(2, hi) // 2 Promise { 'hi' } | |
| console.log(3, hiAgain) // Promise { <pending> } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment