booklore

JavaScript: The Good Parts

Unearthing the Excellence in JavaScript

sufficient

reading path: overview → analysis → narration


overview

Overview

JavaScript: The Good Parts (2008) by Douglas Crockford is a landmark book that transformed how developers understand JavaScript. Before this book, JavaScript was widely dismissed as a toy language. Crockford identified the subset of JavaScript that is reliable, expressive, and beautiful — and created a roadmap for writing quality JavaScript.

The book is short (176 pages) but dense with insight. Crockford's opinionated approach — identifying good parts (functions, objects, arrays) and bad parts (global variables, ==, with, eval) — gave developers a mental model for writing clean JavaScript.


Key Takeaways

  1. JavaScript has a beautifully designed functional core. First-class functions, closures, and lexical scoping are its best features.

  2. Prototypal inheritance is simpler than classical. Objects inherit directly from other objects — no classes, no constructors, no confusion.

  3. Avoid the global scope. Use namespacing or module patterns to prevent global variable pollution.

  4. Use === instead of ==. The == operator performs type coercion that leads to subtle bugs.

  5. Understand the this keyword. Its value depends on how a function is called, not where it is defined.

  6. Arrays are objects. Use array literals, not new Array(), and prefer for loops over for...in for arrays.

  7. JSON is a subset of JavaScript object literals. Crockford discovered and popularized JSON.

  8. Regular expressions are powerful but dangerous. Crockford provides guidance on their safe use.

  9. Use JSLint. Automated code quality checking prevents entire categories of bugs.

  10. Simplify. The best code is the code that does not exist.


Who Should Read

| Reader Type | Why | |---|---| | JavaScript developers | Foundational understanding of the language | | Programmers from other languages | Learn JavaScript's unique strengths | | Anyone teaching JavaScript | Clear framework for what to teach and what to warn against | | Framework developers | Deep understanding of the language under the abstractions |


Who Should Skip

  • Complete beginners to programming
  • Developers who only write TypeScript and never raw JavaScript
  • Those looking for modern ES6+ coverage — the book is from 2008

| Book | Author | Connection | |---|---|---| | Learning React | Alex Banks & Eve Porcello | React builds on JavaScript fundamentals | | Effective JavaScript | David Herman | Deeper modern JavaScript coverage | | You Don't Know JS | Kyle Simpson | Comprehensive modern JavaScript series |


Final Verdict

A classic that changed how developers think about JavaScript. Still relevant despite its age, though modern JavaScript has addressed many of the bad parts Crockford identified. Essential context for any serious JavaScript developer.

Rating: 8/10 — Opinionated, insightful, and historically important. Supplement with a modern JavaScript resource.


content map

The Good Parts Philosophy

Crockford's central claim: JavaScript contains a beautiful, elegant, powerful core — but it also contains problematic features. The key to writing good JavaScript is to use the good parts and avoid the bad ones.

graph TD
    subgraph Good_Parts["The Good Parts"]
        F["Functions as first-class objects"]
        O["Object literals"]
        A["Array literals"]
        PT["Prototypal inheritance"]
        CL["Closures"]
        RG["Regular expressions"]
    end

    subgraph Bad_Parts["The Bad Parts"]
        GV["Global variables"]
        EW["with statement"]
        EV["eval function"]
        EQ["== (loose equality)"]
        SP["Switch fall-through"]
    end

    Good_Parts --> JS["Quality JavaScript"]
    Bad_Parts --> AV["AVOID"]

Functions

Functions are the core building block of JavaScript.

graph TD
    subgraph Function_Types["Functions in JavaScript"]
        FD["Function Declaration<br/>function foo() {}"]
        FE["Function Expression<br/>const foo = function() {}"]
        AF["Arrow Function<br/>const foo = () => {}"]
        IIFE["IIFE<br/>(function(){})()"]
        CB["Callback<br/>setTimeout(fn, 100)"]
    end

    subgraph Concepts["Key Concepts"]
        SC["Scope Chain<br/>Lexical scoping"]
        CL["Closure<br/>Functions remember scope"]
        TH["this binding<br/>Context-dependent"]
        AR["arguments object<br/>Array-like parameters"]
    end

    Function_Types --> Concepts

Object Creation

Crockford recommends object literals and the module pattern over classical constructor functions.

| Pattern | Good Part? | Use Case | |---------|-----------|----------| | Object literal | Yes | Simple objects, namespaces | | Module pattern (IIFE) | Yes | Private state, encapsulation | | Constructor with new | Caution | Use with capital letter convention | | Object.create | Yes | Prototypal inheritance | | Class syntax (ES6) | Modern | Not covered in the book |


Prototypal Inheritance

JavaScript uses prototypal inheritance — objects inherit directly from other objects.

graph TD
    subgraph Prototype_Chain["Prototype Chain"]
        OBJ["Object.prototype"]
        MY["myObject<br/>{ name: 'test' }"]
        MY -- "__proto__" --> OBJ
    end

    subgraph Classical["Classical (for comparison)"]
        CLS["Class Animal"]
        CLS --> DOG["new Dog()"]
        CLS --> CAT["new Cat()"]
    end

Arrays

JavaScript arrays are objects with special length behavior.

flowchart LR
    subgraph Array_Best["Array Good Parts"]
        L["Array literal []"]
        PS["push / pop"]
        SH["shift / unshift"]
        SP["splice"]
        SL["slice"]
        FR["forEach / map / filter"]
    end

    subgraph Array_Worst["Array Bad Parts"]
        FO["for...in on arrays"]
        DE["delete (use splice instead)"]
    end

Regular Expressions

Crockford provides a concise guide to regex patterns useful for everyday JavaScript programming.

| Pattern | Matches | |---------|---------| | /^\s*$/ | Empty or whitespace-only | | /^[\w-]+(.[\w-]+)@/ | Email-like identifiers | | //*[\s\S]?*// | Block comments |


Style and Conventions

Crockford strongly advocates for:

  1. Consistent indentation (2 spaces)
  2. Always use curly braces for blocks
  3. Use === and !== exclusively
  4. No space between function name and parameters
  5. Capitalize constructor functions
  6. Declare variables at the top of their scope

Reading Guide

| Chapter | Topic | Est. Time | Priority | |---------|-------|-----------|----------| | 1-2 | Philosophy and syntax | 30 min | Essential | | 3-4 | Functions and objects | 1h | Essential | | 5 | Inheritance | 45 min | Essential | | 6 | Arrays | 30 min | Essential | | 7-8 | Regex and methods | 45 min | Important | | Appendix A | The Awful Parts | 30 min | Essential | | Appendix B | The Bad Parts | 30 min | Important | | Appendix C | JSLint | 20 min | Optional |


analysis

Strengths

  • Historical importance. The book that transformed JavaScript from a dismissed toy into a respected programming language.
  • Opinionated clarity. Crockford's strong opinions give developers a clear framework for what to use and what to avoid.
  • Concise and focused. At 176 pages, it gets to the point and never wastes the reader's time.
  • JSON discovery. The book explains the origins of JSON, which Crockford discovered and popularized.
  • JSLint advocacy. The emphasis on automated linting was ahead of its time and influenced the ESLint ecosystem.

Weaknesses

  • Severely dated. Written in 2008, it predates ES6, TypeScript, async/await, modules, and modern tooling.
  • Overly dogmatic. Some of Crockford's "bad parts" are now considered acceptable when used correctly (e.g., with statements in specific situations).
  • Missing modern patterns. Promises, destructuring, arrow functions, and classes are not covered because they did not exist.
  • TypeScript gap. The book's advice on avoiding "classical" patterns is contradicted by TypeScript's class support.

Criticism

The "Stopped Time" Critique

Crockford's influence was so strong that some developers still avoid JavaScript features that are now standard and well-supported. His dogmatism created unnecessary fear about the language.

The "Not Endorsed by the Community" Critique

Modern JavaScript has evolved beyond Crockford's "good parts" subset. The broader community now embraces classes, async/await, and modules that Crockford would have likely criticized.


Comparison with Similar Books

| Book | vs. JavaScript: The Good Parts | |------|------------------------------| | You Don't Know JS (Simpson) | Comprehensive modern JS, 6 volumes | | Effective JavaScript (Herman) | Deeper, more nuanced, covers ES5 | | JavaScript: The Definitive Guide (Flanagan) | Complete reference, updated regularly |


Historical Context

Published in 2008, this book arrived at a low point for JavaScript's reputation. The language was primarily used for browser form validation and simple interactions. Crockford's book helped start the rehabilitation of JavaScript that culminated in the ES6 revolution and the dominance of Node.js.


Final Assessment

| Dimension | Rating | Notes | |-----------|--------|-------| | Depth | 8/10 | Excellent for its subject matter | | Breadth | 4/10 | Narrow coverage by modern standards | | Readability | 9/10 | Clear, concise, opinionated | | Practical Utility | 5/10 | Must supplement with modern resources | | Lasting Value | 6/10 | Historical value > practical today | | Overall | 6.5/10 | Important context, out of date as a guide |


narration

Welcome to BookAtlas. Today, we explore JavaScript: The Good Parts by Douglas Crockford, published in 2008 by O'Reilly Media. At just 176 pages, this is a landmark book that transformed how developers understand JavaScript.

Before this book, JavaScript was widely dismissed as a toy language used for browser form validation and simple animations. Crockford, who was a senior architect at Yahoo, identified the subset of JavaScript that is reliable, expressive, and beautiful, and created a roadmap for writing quality JavaScript.

Crockford's central claim is that JavaScript contains a beautiful, elegant, powerful core, but it also contains problematic features. The key to writing good JavaScript is to use the good parts and avoid the bad ones. This opinionated approach was revolutionary at the time and gave developers a clear framework for what to use and what to avoid.

The good parts, according to Crockford, include first-class functions, object literals, array literals, prototypal inheritance, closures, and regular expressions. The bad parts include the global scope pollution, the with statement, the eval function, the loose equality operator, and switch statement fall-through. Much of this advice has stood the test of time.

The book's treatment of functions is outstanding. Crockford explains that functions are the core building block of JavaScript. They are first-class objects that can be created dynamically, passed as arguments, and returned from other functions. Understanding lexical scoping and closures is essential to mastering JavaScript.

Crockford's advocacy for prototypal inheritance over classical inheritance was controversial but influential. He argues that objects should inherit directly from other objects without the indirection of classes and constructors. This approach, using Object.create, is simpler and more powerful for many use cases.

The book made one lasting contribution to the entire software industry. Crockford discovered and popularized JSON, the JavaScript Object Notation that has become the universal data interchange format on the web. The book explains how JSON is a subset of JavaScript object literals and why it is superior to XML for data representation.

The book's most significant weakness is its age. Published in 2008, it predates ES6, TypeScript, async and await, modules, and modern tooling entirely. Some of Crockford's advice, like avoiding constructor functions entirely, has been superseded by the community's embrace of class syntax. However, his core message about focusing on the good parts of the language remains valid.

On the BookAtlas scale, JavaScript: The Good Parts earns a 7 out of 10. It is a classic that changed how developers think about JavaScript, essential context for any serious JavaScript developer. But modern JavaScript has addressed many of the bad parts, and the book must be supplemented with a modern resource that covers ES6 and beyond. This has been a BookAtlas narration of JavaScript: The Good Parts by Douglas Crockford. Thanks for listening.