Summary

This chapter discussed how we can face asynchronous programming in JavaScript. Starting with the asynchronous nature of the JavaScript's runtime execution flow, we explored how to manage events using callback functions. We saw that, although callbacks are widely used to manage asynchronous code, they are not so effective. A heavy use of callbacks leads to unreadable code and the so-called callback hell—a maze of code difficult to read and understand. Moreover, managing asynchronous code with callbacks do not allows us to catch failures.

Promises can help us get more control on asynchronous code. We have seen the standard Promise's API of ECMAScript 6 and shown how to use them in order to catch results and failure and synchronize multiple ...

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.