Skip to content

Instantly share code, notes, and snippets.

@homostellaris
Last active February 26, 2024 07:31
Show Gist options
  • Select an option

  • Save homostellaris/35280ae5382fe8987682fe476b19a04b to your computer and use it in GitHub Desktop.

Select an option

Save homostellaris/35280ae5382fe8987682fe476b19a04b to your computer and use it in GitHub Desktop.
Promise execution order
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