Asynchronous programming is a part of the nature of JavaScript since its birth. Regardless of the runtime environment of JavaScript, you cannot ignore the execution of asynchronous code, whether it is the management of user's interaction with a graphical interface or the interaction with a server or a hardware component of the system.
This chapter will discuss how to manage asynchronous code in JavaScript by analyzing the classical approach based on callback functions, pointing out its intrinsic drawbacks and exploring new approaches such as the ones based on Promises and Generators.
The following topics will be discussed in the chapter:
Events and asynchronous calls
Callback functions
Troubles with callbacks
ES6 Promises
A Generator-based approach