jskatas.org Continuously Learn JavaScript. Your Way.

Promise: the API

Promise API overview.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Promise API overview

  • new Promise() requires a function as param

resolving a promise

  • via constructor parameter new Promise((resolve) => { resolve(); })
  • using Promise.resolve()

a rejected promise

  • using the constructor parameter
  • via Promise.reject()


  • Promise.all([p1, p2]) resolves when all promises resolve
  • Promise.all([p1, p2]) rejects when a promise is rejected


  • Promise.race([p1, p2]) resolves/reject when one of the promises resolves/rejects
  • Promise.race([p1, p2]) rejects when one of the promises rejects
  • Promise.race([p1, p2]) order matters (and timing)