Pillar 3: Types and Coercion

The third pillar of JS is by far the most overlooked part of JS’s nature.

The vast majority of developers have strong misconceptions about how types work in programming languages, and especially how they work in JS. A tidal wave of interest in the broader JS community has begun to shift to “static typing” approaches, using type-aware tooling like TypeScript or Flow.

I agree that JS developers should learn more about types, and should learn more about how JS manages type conversions. I also agree that type-aware tooling can help developers, assuming they have gained and used this knowledge in the first place!

But I don’t agree at all that the inevitable conclusion of this is to decide JS’s type mechanism is bad and that we need to cover up JS’s types with solutions outside the language. We don’t have to follow the “static typing” way to be smart and solid with types in our programs. There are other options, if you’re just willing to go against the grain of the crowd, and with the grain of JS (again, more on that to come).

Arguably, this pillar is more important than the other two, in the sense that no JS program will do anything useful if it doesn’t properly leverage JS’s value types, as well as the conversion (coercion) of values between types.

Even if you love TypeScript/Flow, you are not going to get the most out of those tools or coding approaches if you aren’t deeply familiar with how the language itself manages value types.

To learn more about JS types and coercion, check out Book 4, Types & Grammar. But please don’t skip over this topic just because you’ve always heard that we should use === and forget about the rest.

Without learning this pillar, your foundation in JS is shaky and incomplete at best.