Unsettled Promises

Learn how unsettled promises are created and executor errors are caught.

Creating unsettled promises

New promises are created using the Promise constructor. This constructor accepts a single argument: a function called the executor, which contains the code to initialize the promise. The executor is passed two functions, resolve() and reject(), as arguments. When the executor has successfully finished, we call the resolve() function to signal that the promise is resolved, or we call the reject() function to indicate that the operation has failed. Here’s an example using the old XMLHttpRequest browser API:

Get hands-on with 1200+ tech skills courses.