Chapter 1Understanding JavaScript Events

Events. How do they work? Confusion about JavaScript’s asynchronous event model is as old as JavaScript itself. Confusion leads to bugs, bugs lead to anger, and Yoda taught us the rest….

Yet at heart, JavaScript events are both conceptually elegant and practical. Once you’ve accepted the language’s single-threaded design, it feels like a feature rather than a limitation. It means that your code is uninterruptible and that the events you schedule line up in an orderly fashion.

In this chapter, we’ll take a tour of JavaScript’s asynchronous mechanisms and dispel some common misconceptions. We’ll see what setTimeout really does. Then we’ll discuss handling errors in callbacks. Finally, ...

Get Async JavaScript 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.