Promises

In JavaScript, many actions are asynchronous. A great example of this is an AJAX request. When the request is sent, you do not know when or even if a request will be returned. This is where promises come in.

A promise is an object that will promise to run a function once an asynchronous event has happened. In our example, the event will be the request returning. This could be in a few milliseconds or longer, depending on the timeout setting.

In addition to tracking successful events, promises can be rejected. This allows the object that was waiting for the response to do something different.

Note

Visit https://promisesaplus.com/ for the complete specification for using promises in JavaScript. Promises or promise-like objects are applicable ...

Get Web Developer's Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.