justjavascript.com. What a great little course. It teaches you a wonderful mental model for memory management in JS… except… it does it without referring to memory management. It’s created in part by Dan Abramov.
It starts off different from the get go, visualizing your javascript runtime as a solar system! It asks you to put aside your prior knowledge about memory layouts and instead, embrace ‘rewiring’ your brain to think in a new way. Coming from a background of C programming and an appreciation for low level languages, I was pretty apprehensive, but I’m glad I took the course and learned some new things.
It’s a text based course. However it’s intermixed with calming diagrams, gif’s, quiz’s and interactive drawing through an embedded https://excalidraw.com/. More than anything, it’s worth a read as an exemplary model of how to make a concise course that leaves the reader feeling like they had fun.
Below are some of my notes from the course. These are mostly for me.
Notes:
summary:
Everything is a value. Immutable values can be thought of as distant stars in a solar system, you can only point to them. Strings, numbers, null, undefined, booleans (primitives). The only mutable values are objects and functions. However, don’t think of those as ‘boxes’ or containers of variables. Instead think of them as simply values, and their properties are pointing (the wire model) to other values outside of the object itself.
Strings are not objects. Not everything is an object in js. Think instead in values. Every object has a __proto__
pointer to a parent object that allows the sharing of functionality. People wanted to code in a class based system so JS introduced new
and prototype
(not used anymore with the advent of classes). Class’s are still implemented via __proto__
like this. Overall, remember to think as a wire model, where objects and functions are mutable, and everything else is not, and everything is a value. Neat!
The mental model is built on wires. Forget low level details like stacks and heaps, and just think wires.
Variables are wires. They point to values. Values can be a primitive, immutable values (strings, numbers, bigints, booleans, null, undefined, symbols) or mutable values (functions and objects). The course describes a wonderful metaphor where you visualize yourself within a solar system. Immutable values are distant starts, you can only point to them. Mutable values are nearby planets you can touch.
Instead of talking about low level details, it encourages the reader to set those aside. What! I thought to myself. Isn’t that how I gain a deeper understanding of a programming language? Isn’t that my secret ability? I know what the stack and heap are and can reason about them, why would