< MY SKILLS PAGE

Self-Study of

Eloquent JavaScript, 4th ed. (2024)

Textbook by Marijn Haverbeke

Self-study by Nicolas Hernandez

Full textbook made available online by the author

Preamble

This is a self-study effort from January 2025. Scripts I wrote for the applicable chapter exercises are at the bottom of this page's source code.

I've been eying this textbook for a few days now, but since I have this website, I figure this is a good place to host my notes in an environment where I can actually execute JavaScript. I didn't have a place to put it, though, so I changed my site structure to add supporting pages that lead to this one.

All this just to start studying? Yes. I enjoy the content of the work and the learning involved, plus an investment in myself pays dividends in the future. What kind of fool works without being told? One who's curious or creative or future focused or otherwise self-driven... that kind of fool! And now, I'll fool around with the content of this book.

Eloquent JavaScript, 4th Edition, by Marijn Haverbeke
This page is themed after the cover of the book.

Chapter 0 - Introduction
"A sense of what a good program looks like is developed with practice, not learned from a list of rules."

This chapter discusses very basic concepts on the what & why of programming & JavaScript, so the part that shines out to me is the above quote. The author isn't teaching from a place of telling you what should be done, but rather from preparing you to tell yourself what should be done.

One who's not an artist doesn't know the rules. A good artist knows the rules well and follows them well. A great artist knows the rules well... and breaks them. Not by simply ignoring them, but by deconstructing the very reasons those rules exist.

The author and I share some values. That's what I've learned from this book's introduction.


Chapter 1 - Values, Types, and Operators
That's not a bug, it's a feature.

This chapter had lots of basic operations, plus the nullish operator ("??"), which browsers didn't even widely support until 2020. I'm not sure a great number of people formally educated until just recently would even know about it if they're not doing occasional reviews of the base technology like I'm doing here. Even then, lots of documentation was made before this was well-supported. It's a case where the latest textbook edition is necessary if it's to supply this knowledge. Sure enough, this feature isn't in the same textbook's previous edition.

These are some concepts from this chapter that I haven't been using in my JavaScript:

Here are some concepts I know that supplement this chapter:

Between these two lists, some of them are maybe not intended by the language, but they're all consistent enough to be used as outright features.


Chapter 2 - Program Structure
The devil's in the details.

I already knew everything that was in this chapter, or at least, I knew everything it intended for me to know. Of the (offhand-mentioned) list of reserved keywords, I haven't been using most of the object-oriented ones in my JavaScript. The keywords async and await are conspicuously missing from the chapter's list of keywords, and I don't think I've ever used the keywords with or yield. None of this is in the intended scope of the chapter, but if I'm brushing up on my JavaScript, I think it's good to look out for places where I can be thorough.

The with keyword is deprecated, but here's my first script using yield. The below elements generate a number between the lower & upper bounds, then stops generating after 10 yields, unless you change the bounds:





[press the button to yield a value from a generator function]

Chapter 2 Exercises


Chapter 3 - Functions
Every instruction is made of smaller instructions, every little bit's got a million bits.

These chapters are getting longer now. There's a little quirk to be found in a chapter that instructs how to write sets of instructions, while part of that instruction is an example specifically about recursion.

The book doesn't specifically endorse one way or the other when it comes to creating functions, but I'm bought in on the arrow functions. I always thought that unless two functions must reference one another, it's bad form to use a function before it's defined in the code. So I didn't use this quirk of function fun() {} declaration notation and wound up forgetting about it. Plus, this notation never lets you define fun as a constant, and I always define functions as const whenever possible. const fun = () => {} is valid JavaScript, and const function fun() {} is not.

I should also note that I'd forgotten about default function inputs that replace undefined ones, where a function is defined (a, b = 'default input') => {} so that if a function call is missing an argument, it can fill b in with the assignment expression in the function arguments definition.

Chapter 3 Exercises


Chapter 4 - Data Structures: Objects and Arrays
This is the longest chapter in the book!

Sure enough, my ability with objects in JavaScript has been pretty under-utilized. In fact, I probably learned things in the wrong order the first time around, because I never use the in or delete keywords, because I didn't understand them when I first learned about them, because I wasn't using JavaScript objects until later on! So here's another list of things I haven't been using in my JavaScript:

In spite of the increasing verbosity of the chapters, I know some things would remain a complete mystery for an actual beginner reading this book. In the "Destructuring" section, it says you can use square brackets to "look inside" of an array value to bind its contents, but it doesn't give an example, making this a nearly indecipherable remark if you don't see an example (let [a, b, c, d] = someArrayWith4Elements).

The chapter had a bit of math, too, which is cool. It sometimes takes lots of math & working out general formulas to make my scripts act the way I want them to, so seeing someone else using math as part of their process is refreshing. That's surprisingly uncommon for what programming fundamentally is.

Chapter 4 Exercises


Chapter 5 - Higher-order Functions
Yo, dawg, I heard you like functions.

Well, I looked ahead and saw that chaper 4 was the longest chapter in the entire book. This chapter was significantly shorter, though it also covers inbuilt language specifics that are wheels I've tended to reinvent rather than using their implementations that are available by default. Hopefully by having run by these here, I'll have better recall when it comes time to use them:

Chapter 5 Exercises


Chapter 6 - The Secret Life of Objects
It's short for "classification."

There's something so arcane about the Symbol type. When a Symbol is instantiated, I imagine a unique glyph appearing and being used as the label for whatever property it corresponds to.

This chapter had more tinkering with objects, so here are some more concepts I haven't been using in my code:

I already knew about maps, the "extends" & "static" & "super" keywords work like in Java. The syntax is similar, but you can tell that all things about JavaScript classes are syntactic construct made by composing objects & functions such that they can look & act like Java classes, with the syntax hiding all of the complexity required for that underneath. It's not a fundamental of the language like it is in Java; it's a bunch of other concepts all coming together to make this, which makes it harder to wrap your head around, despite the code itself being mostly familiar.

Chapter 6 Exercises


Chapter 7 - Project: A Robot
Go, RoboJackets!

It's a program that aggregates what's been covered so far and makes a little crawler that navigates around a graph data structure. It's pretty walkthrough-ey and is about as much of a project as any one the DHTML effects I noodled out to add motion to some pages on this site. It adds a couple of new things, though:

Chapter 7 Exercises


Chapter 8 - Bugs and Errors
I start from the wall outlet, then I check the power supply unit, then I check the motherboard, ...

About the only debugging feature I've used in JavaScript was exception handling & console logging, so this is mostly new territory for me. Here are some features to keep a note of from this chapter:

Chapter 8 Exercises


Chapter 9 - Regular Expressions
It's slow, it's cryptic, it can always be done another way, but it is powerful.

It's a one-line solution for otherwise many-line problems. Sure, it's general-use code and has the common pitfalls when compared against purpose-built code where it's applicable, but it wraps a LOT of functionality into a relatively tiny package.

Here's a long list of concepts for regular expressions in JavaScript, enough to take me from zero to practical:

And that's pretty much everything. A shorter list of just the basics is in the summary to this chapter. The book suggests the tool Debuggex for quick quality assurance of regular expressions, to ensure that a regex will work as intended.

Chapter 9 Exercises


Chapter 10 - Modules
The bread & butter needed for the frontend frameworks to jam.

It's just imports & exports, how they work, and how to leverage that for JavaScript software design. Here are the chapter's concepts about ECMAscript / ES modules, plus a little extra that's helpful for my learning context:

As imports & exports were only implemented well after JavaScript was a standard in programming, a common proto-module system agreed upon by developers was CommonJS, which uses a "require" function and "exports" object to modularize JavaScript dependencies:

And here are some other pointers from the chapter:

Chapter 10 Exercises


Chapter 11 - Asynchronous Programming
MEANWHILE,

I sort of understand Promises, await, and callback functions going into this, enough that I actually use them in my coding, but going by the depth of the last chapters, I'm up for some new surprises. And I know enough to know that Promises & async await deserve their own sections in my notes...

Callback functions:

Promises:

Async & await

Miscellaneous

ASYNC FUNCTIONS RETURN PROMISES. That's a big thing to not forget, because an async function is a easier to interpret than the Promise constructor

Chapter 11 Exercises


Chapter 12 - Project: A Programming Language
Yo, dawg, I heard you like programming languages.

I'd call this one a more proper textbook project, since it mostly just uses knowledge from earlier in the book. There are some other JavaScript Error types this uses, like SyntaxError and TypeError, but other than that, it's almost all an application of previous concepts, sprinkled in with some theory.

This chapter introduces syntax trees, parsers, interpreters, and compilation, all in terms of the work that's done in this chapter. The parser turns the raw code into a syntax tree, the evaluator executes the code defined by the syntax tree, and that all adds up to an interpreter for the "Egg" language built in this chapter. Lastly, compilation is taking it a step further and preprocessing the executable code into a further optimized version of the interpreted code, frontloading as much of that processing as possible and outputting a compiled version of the code that runs faster than the language just being interpreted. For example, code in the Egg language from this chapter might compile into JavaScript, and instead of running the Egg code directly, you would compile it into JavaScript code and then run that JavaScript code instead of the Egg interpreter.

Chapter 12 Exercises


Chapter 13 - JavaScript and the Browser
Back in familiar territory again...

This chapter is a bit of background info on the Internet & how we get from zero to JavaScript. If I was formally educated in computer science, I'd probably know all about TCP/IP and the distinction between the World Wide Web and the Internet. I knew about communication protocols from my time with industrial controllers & IoT, protocols like Modbus and DeviceNet and OPC/UA. They're just languages that machines speak, and as long as both machines speak that language, they can communicate meaningfully with each other. HTTP is a structured request-and-reply resource exchange protocol / language, and it happens over TCP, which is a listen-and-connect protocol / language that manages routing to listening ports. The World Wide Web is the set of these standards & languages, with the "Web" referring to the interconnections between many devices. A URL points to a protocol ("https://"), a server address / domain name to send a request to via that protocol ("nickhz.live/"), and a path to a specific resource within that server to request ("professional/self-development/eloquent-javascript-2024/index.html").

After that, it's HTML & embedding scripts. The character entities like &gt; and &amp; are mentioned, of which there are many more, but a small subset of character entities is generally sufficient to meet the needs of an HTML document. The general HTML syntax & embedding JavaScript is demonstrated by this Web page. If this chapter had any exercises, this page would be sufficient to fulfill them. Press F12!

Chapter 13 Exercises - There are none!


Chapter 14 - The Document Object Model
Yo, dawg, I heard you like docum--

It's still familiar territory for me, but this chapter also draws out alternative ways to do some things.

Chapter 14 Exercises


Chapter 15 - Handling Events
Listening is arguably the most important part of communication.

Event listeners, event handlers, event types, a bit of event bubbling (though the text doesn't use that word specifically), all stuff that I generally know but has some extra detail that I want written down. Not all of this is in the text, but reading the text did make me think of including all the things that are here:

Chapter 15 Exercises


Chapter 16 - Project: A Platform Game
"The gravity strength, jumping speed, and other constants in the game were determined by simply trying out some numbers and seeing which ones felt right. You can try experimenting with them." And that, I did.

It all feels so disconnected until it all comes together. I think it would be better presented as one big long script that can be used as a reference during the reading, or even better: emphasize that the reader should write out this program in order to understand it best.

At least for me, seeing the program all in one place is more readable than seeing little bits of it interspersed throughout the chapter. It makes all the arguments sent to the functions less cryptic. I guess there's a meta-lesson there, about the risks of over-modularization, but learning the lesson in real time by having to reference other parts of the page for each line of code made the exercises probably more painful than they needed to be. Albeit, over time spent with custom library-like code like this, you get used to the names & abstractions & structure of it, just not if it's a library that's only relevant for one chapter in a textbook. You just don't spend enough time with it to really know it holistically before you have to work with it, and it's like working with an alien toolbox. But we soldier on.

Chapter 16 Exercises


Chapter 17 - Drawing on Canvas
This one might be the most exciting chapter for me! The browser yields many under-explored artforms. Up to this point, have I been drawing without a canvas?

I've had my eyes on SVG & canvas. The book doesn't go much into SVG, which is understandable since JavaScript isn't a requirement for its use. Canvas is the mainstay, but there's enough covered to think that one chapter in a textbook is more of just an introduction than anything else. It's a welcome one, since one of the troubles with learning Canvas is having an idea of where to start, but now that I've peeked at the Canvas 2d context API, I realize that this chapter actually covers a significant chunk of what it can do. Its power comes from getting creative with the toolset, which I thought would've been bigger for all that it's capable of. But it really goes to show how effective this chapter is at throwing you into canvas concepts.

After this, I'm more confident in exploring the other powerful browser rendering techs instead of just defaulting to DHTML & CSS3 for artistic Web pages. And there are some visual effects I've seen that are suddenly a lot less mysterious now. Maybe I'll be making mysteries for those after me to ponder, too!

Chapter 17 Exercises


Chapter 18 - HTTP and Forms
Now, let's take a look under the hood.

I think that starting with the actual text of the protocol communications is a great way to start when teaching fetch. A lot of confusion can be avoided with a concrete grounding like this, demystifying what lies beneath what's being taught.

Chapter 18 Exercises


Chapter 19 - Project: A Pixel Art Editor
Redux?

This is the last of the browser JavaScript chapters. The project structure here echoes a React application with the component-based structure & state management, and I don't think that's an accident. Looking back at previous editions, then sure enough, this structure only came about when React hit the author's lips. I can appreciate the thoughtfulness of directing the skill in a way that's marketable.

That said, I believe that knowledge of plain JavaScript, like from this book, will get a lot more mileage than knowledge of any particular UI library or framework that's built on top of JavaScript. Over the course of this book, I've learned more about all the frontend frameworks at once. It's fine enough to see how a stateful frontend application is structured without so many layers of abstraction, but I put this architecture firmly in the category of being a preference or tool rather than being the one right way to do things. It's a single methodology out of the many that can be composed with this knowledge.

Chapter 19 Exercises


Chapter 20 - Node.js
Into the last terminal.

Having the client & server both speak the same language is absolutely stellar for understanding what's going on in the client-server interaction. For all the flak you can give to server-side JavaScript, Node.js and browser JavaScript are a powerful toolset when it comes to learning & teaching about fullstack applications.

As this chapter doesn't aim to provide an exhaustive course on Node, here are important links provided by the text to use & learn of these tools in greater depth:

Chapter 20 Exercises


Chapter 21 - Project: Skill-Sharing Website
The final stretch!

This bit was essentially a meta-exercise in interpreting a front & backend project that's already pre-written. That's an important professional skill to have, sure, but I also appreciate it as victory lap for the reader to be able to say, "yes, I know JavaScript."

This chapter's entire project is somewhat less complicated than the one I wrote for chapter 20's final exercise, but that's at least partly because it offloads much of the complexity with its structure and its dependencies. I might have skill, but the author Marijn has skill AND experience.

They assert that creating UI elements using an element creation function that takes the tag name, tag attributes, and child elements has led to messy code, but I think it's pretty clean, so clean that it's easy to know how to make it cleaner. They've basically built the JSX that underlies React.

Chapter 21 Exercises

These exercises are modifications for the skill-sharing application code outlined in this chapter.


Reflection

I would recommend this book to others who want to learn JavaScript. I still believe I was fairly capable with browser JS from the beginning, but now, it feels like I've completed a toolbox that I didn't even know was incomplete! It's handed me a lot of leads for moving forward with, too. I think the intended route here is React, but I'm also interested in websockets and SVG. It's made several concepts like canvas & asynchronous code more approachable, too.

Because JavaScript is supported by the ecosystems built on it, the more complete knowledge of the pure language can feel like having all the cheat codes. I can imagine how more things must work behind the scenes now, like how JSX could be implemented similarly to how the Egg programming language from chapter 12 was, or how React & Angular components are essentially just the stateful class components created in the final chapter & handled as ES modules, with the syntactic sugar of JSX added to them. I can see through things that were once arcane, and it's thanks to the understanding from this book.

The application from the final chapter was a logical conclusion, a webapp whose UI doesn't even render without the browser running a mess of JavaScript. The mainstream Web UI frameworks have reached similar conclusions before, too, and I personally don't agree with it. There are performance reasons & bad-practice reasons & probably environmental reasons that can support me on that, but my personal core for being against it is that JavaScript should be reserved for the good stuff. It's the ace in the hole for making the impossible possible in Web UI, and when you make it handle every menial little task on the browser, what's happened is that you spread its capability thin in the developer's mind and wind up underselling what JavaScript is truly capable of. It's powerful, and there's less & less thought about that power as people abstract it away into Web frameworks that regularly try to put it in your head that you need an entire JavaScript framework for an interactive application. I don't need a single line of JavaScript for basic functions like single-url pagination or motion graphics rendering to work. The frameworks make applications that are maintainable & easy to collaborate on. They're tools that help the bottom line for larger teams, not a statement on the one right way to do things. Converging on it as if it IS the one right way to do things is probably getting at least a little caught up in the current trends, but as it's also being taught as a professional skill to help people get further along in the actual software industry, I think that part of it is commendable.

The last project did feel more like a victory lap than anything, and it makes me glad that I overcomplicated the final exercise from chapter 20, rebuilding that from scratch & adding my own new features instead of sticking strictly to the book. It gave me the chance to compose everything from the whole text together into a program that's truly my own, where I took it as a problem statement to create a solution for rather than as a LeetCode-esque exercise to figure out an abstract algorithm. I now have an extensible application that works as my own custom & quickly searchable file manager, and it's thanks to the application requested by this book. With some polish, it can even become something you can sell to people, and that crosses a line from being a textbook exercise to being a peek into the vision of an engineer, the vision of the one who wrote this book.

I have my own visions, too: problems to solve and solutions to be made. And with this book now behind me, I'm definitively better prepared for that future.