Chapter 8. Effective JavaScript
JavaScript is one of the most widely deployed programming languages in history, and most of us learned it sideways. We picked it up from blog posts, Stack Overflow answers, and whatever the framework du jour demanded. We got things working, and working was usually good enough. But somewhere between the first callback and the hundredth async/await, a gap opens between code that works and code that works well.
This chapter is about closing that gap. Not with linting rules or style guides, but by understanding the mechanisms underneath: the event loop that schedules your callbacks, the bundler that analyzes your dependency graph, the error propagation chain that determines who sees what when things break. When you write code that works with these mechanisms, everything flows. When you work against them, you get mysterious bugs, bloated bundles, and silent failures that no amount of debugging will explain.
In Chapter 2, we explored the tooling ecosystem: npm, build tools, and the dependency graph. In Chapter 4, we saw how HTTP’s request-response model shapes communication and how every fetch call is an asynchronous operation that might fail. This chapter goes a level deeper, into the language itself and the runtime that executes it.
In this chapter, we will learn:
-
Why JavaScript’s multi-paradigm nature requires discipline, not dogma, and how the wrong abstraction creates more bugs than it prevents.
-
How JavaScript’s asynchronous model works from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access