Chapter 9. Handling events
Asynchronous Coding
After this chapter youâre going to realize you arenât in Kansas anymore. Up until now, youâve been writing code that typically executes from top to bottomâsure, your code might be a little more complex than that, and make use of a few functions, objects and methods, but at some point the code just runs its course. Now, weâre awfully sorry to break this to you this late in the book, but thatâs not how you typically write JavaScript code. Rather, most JavaScript is written to react to events. What kind of events? Well, how about a user clicking on your page, data arriving from the network, timers expiring in the browser, changes happening in the DOM and thatâs just a few examples. In fact, all kinds of events are happening all the time, behind the scenes, in your browser. In this chapter weâre going rethink our approach to JavaScript coding, and learn how and why we should write code that reacts to events.
Brain Power
You know what a browser does, right? It retrieves a page and all that pageâs contents and then renders the page. But the browserâs doing a lot more than just that. What else is it doing? Choose any of the tasks below you suspect the browser is doing behind the scenes. If you arenât sure just make your best guess.
Knows when the page is fully loaded and displayed. |
Keeps track of all the clicks you make to ... |
Get Head First JavaScript 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.