JavaScript Promises

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • new Promise( /* executor function: */ function(resolve, reject) { })
  • promise.then(onFulfilled[, onRejected])
  • promise.catch(onRejected)
  • Promise.resolve(resolution)
  • Promise.reject(reason)
  • Promise.all(iterable)
  • Promise.race(iterable)

Remarks

Promises are part of the ECMAScript 2015 specification and browser support is limited, with 88% of browsers worldwide supporting it as of July 2017. The following table gives an overview of the earliest browser versions that provide support for promises.

ChromeEdgeFirefoxInternet ExplorerOperaOpera MiniSafariiOS Safari
321227x19x7.18

In environments which do not support them, Promise can be polyfilled. Third-party libraries may also provide extended functionalities, such as automated "promisification" of callback functions or additional methods like progress—also known as notify.

The Promises/A+ standard website provides a list of 1.0 and 1.1 compliant implementations. Promise callbacks based on the A+ standard are always executed asynchronously as microtasks in the event loop.



Got any JavaScript Question?