This book is currently a work in progress. Content is being actively developed and refined.
You Don’t Know JS Yet: Types & Grammar - 2nd Edition
Welcome to the Types & Grammar book, part of the You Don’t Know JS Yet series. This book dives deep into JavaScript’s type system, exploring how values behave and interact in ways that many developers never fully understand.What You’ll Learn
This book confronts the common misconception that “everything in JS is an object” and explores the core value types of JavaScript, specifically the non-object types called primitives.Primitive Values
Explore the 7 primitive types: undefined, null, boolean, number, bigint, symbol, and string
Primitive Behaviors
Learn how primitives behave, their immutability, and type-specific operations
Object Values
Understand objects, arrays, functions, and the difference between primitives and objects
Coercing Values
Master type coercion, both explicit and implicit, and write type-aware code
Key Topics Covered
Understanding Value Types
Understanding Value Types
JavaScript doesn’t apply types to variables or properties (“container types”), but rather values themselves have types (“value types”). Learn the fundamental distinction and why it matters.
The typeof Operator
The typeof Operator
Master the
typeof operator and understand its quirks, including why typeof null returns "object" (spoiler: it’s a historical bug that can’t be fixed).Coercion: Friend or Foe?
Coercion: Friend or Foe?
Challenge the common belief that coercion is “bad” and learn when and how to use it effectively. Discover why
== might be better than === in many cases.IEEE-754 and Number Precision
IEEE-754 and Number Precision
Understand how JavaScript represents numbers using IEEE-754 double-precision floating-point format, and learn to handle precision issues.
Unicode in Strings
Unicode in Strings
Navigate the complexities of Unicode, including surrogate pairs, grapheme clusters, and why string length calculations aren’t always straightforward.
Why This Matters
About This Book
This is the second edition of “Types & Grammar,” completely rewritten to reflect modern JavaScript and deeper insights into the language’s type system. The book takes a controversial stance: coercion isn’t the enemy. With proper understanding, JavaScript’s type system becomes a powerful tool rather than a source of bugs.Getting Started
Ready to challenge your assumptions about JavaScript’s type system? Start with Chapter 1: Primitive Values and prepare to see JavaScript in a whole new light.Read the Foreword
Start with the foreword to set the context
Jump to Chapter 1
Dive right into primitive values

