Promises have been around for a while in JavaScript, but we have never had them in the language itself. In the past we would have had to use a library like q or bluebird. These libraries follow something called Promises/A+ , it is a standard that outlines how a Promise should behave, and it is the spec that ES6 Promises also implement.

A Promise represents the eventual result of some sort of asynchronous operation. Commonly these are used in conjunction with an HTTP request. However, it could actually just be any sort of event that will take some time to return. Promises can be a few different states. When a promise is created it has a ‘pending’ state. From there the Promise can have 2 other states, it can be fulfilled(commonly you will hear the word resolved used here), or rejected.

In ES6 the Promise is a constructor that when instantiated will return a new object. This constructor takes what is called an executor, which is a callback function that has two parameters.

Get hands-on with 1200+ tech skills courses.