Introducing Promises

From the previous considerations, we can conclude that, despite their common usage, callback functions are not so suitable to manage asynchronous programming. They allow us to execute asynchronous code, but we have not a strong control on synchronization, error handling, and code readability.

In last years, an alternative pattern for managing asynchronous code is spreading in the JavaScript community—the Promise pattern.

What are Promises?

Promises are objects that represent a value that we can handle at some point in the future. They can be used to capture the outcome of an asynchronous activity, such as an event, and to manage it in a consistent way. In fact, unlike event handling, using callbacks, Promises guarantees us to ...

Get Mastering JavaScript Object-Oriented Programming 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.