A promise is a type of object that typically wraps around asynchronous code. Promises won't run this code until needed, and they provide methods to extract the final result.
Promises are an ingenious solution. They allow you to wrap your asynchronous code inside an object, and then they provide you with some tools so that you can respond to the asynchronous code when you want to.
To manage asynchronous code, promises have three states:
- Pending: When a promise is first created, it has a status of pending. For example, with setTimeout(), the pending status would apply to the time that it takes for setTimeout() to be run.
- Fulfilled: When the promise has finished running, it has a status of fulfilled. This means that it is ready to pass back a value. In the setTimeout() example, this is after the given number of milliseconds have been run.