After using Promise for a while, I realized the followings might be good to know:

  • The executor function of a promise is executed immediately after creation. That means if you create a Promise object using new, the function you passed in (the executor) will run right after the new statement. 1
    For example, in the following codes:
    var prom = new Promise((resolve, reject) => {
    console.log('1')
    setTimeout(() => {
      resolve('3')
    }, 3000)
    })
    prom.then(console.log)
    console.log('2')
    

The output is:

1
2
3