Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Kyle Simpson

Rating No ratings yet

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A compact, opinionated deep dive into JavaScript’s type system and syntax that explains why coercion, primitives, and grammar quirks behave the way they do. Read it if you already write JavaScript daily but still flinch at `NaN`, `typeof null`, or `[] + {}`. 【Book Arc】 - **Opening (~0%–10%)**: Frames the book’s premise — most developers avoid or misunderstand JS types — and sets up the seven built-in types plus the `typeof` operator, including its famous `null` bug. - **Early (~10%–32%)**: Walks through primitives in detail: `undefined` vs. undeclared (and the `typeof` safety guard), array-likes and conversion, numeric literals in multiple bases, IEEE 754 floating-point pitfalls, and special values like `NaN`, `Infinity`, and `-0`. - **Middle (~32%–48%)**: Covers value vs. reference semantics, then the native constructors (`String`, `Number`, `Boolean`, `Object`, `Function`, `RegExp`, `Date`, `Error`), boxing/unboxing via `valueOf()`, and when constructor forms are actually justified. - **Late (~48%–75%)**: Moves into the coercion controversy — abstract operations like `ToInt32`, implicit vs. explicit conversion, and how coercion shows up in comparisons and arithmetic. - **Ending (~75%–100%)**: Explores grammar nuances: statements vs. expressions, operator precedence, automatic semicolon insertion, and other syntax corners that trip up even experienced developers. 【Key Takeaways】 - **JavaScript has seven built-in types, but `typeof` doesn’t map 1-to-1** (Opening): `typeof null === "object"` is a two-decade-old bug you must memorize, not fix. (Opening) - **`typeof` on an undeclared variable is a safety guard, not a bug** (Early): It returns `"undefined"` instead of throwing `ReferenceError`, which is genuinely useful for feature detection and global flags like `DEBUG`. (Early) - **All JS numbers are 64-bit floats — “integers” are just floats without a fractional part** (Early): This explains `0.1 + 0.2 !== 0.3`, `NaN`’s self-inequality, `Infinity / Infinity === NaN`, and the existence of `-0`. (Early) - **Primitives are passed by value-copy; objects by reference-copy** (Middle): Boxing a primitive in `new Number(..)` does not let you mutate the shared primitive — a common misconception worth internalizing. (Middle) - **Object wrappers around primitives are usually a trap** (Middle): `new Boolean(false)` is truthy, so `if (!a)` never runs. Prefer `Object(..)` for explicit boxing and `valueOf()` for unboxing. (Middle) - **Most native constructors have no good reason to exist** (Middle): `new Object()`, `new Function(..)`, and `new Array(..)` are almost always worse than literals; `RegExp(..)` and `Date(..)` are the exceptions with real use cases. (Middle) - **Coercion is a feature, not a flaw** (Late): Understanding abstract operations like `ToInt32` and implicit conversion lets you use coercion deliberately rather than fearing it. (Late) - **Grammar details — statements vs. expressions, ASI, precedence — cause real bugs** (Ending): These are the corners most developers never formally learn, and where subtle production issues hide. (Ending) 【Reading Tips】 - **Skim the preface and conventions** (~0%–10%); the real content starts with the built-in types chapter. - **Deep-read the numbers and special-values sections** (~19%–32%): `NaN`, `-0`, and floating-point behavior are the highest-yield material for day-to-day debugging. - **Treat the natives chapter as a reference** (~39%–48%): You don’t need to memorize every constructor, but note which ones have legitimate uses (`RegExp`, `Date`, `Error`). - **Slow down on coercion and grammar** (~48%–100%): These are the chapters that change how you read other people’s code; expect to re-read examples. - **Keep a console open**: Every claim in this book is verifiable in a browser or Node REPL — test as you go. 【Coverage Limits】 The excerpts cover the book’s opening through roughly the middle, with only brief glimpses of the coercion and grammar chapters; specific examples and chapter-level detail from the later half are not fully represented here.
Page 4
GRAMMAR You Don’t Know JS: Types & Grammar by Kyle Simpson Copyright © 2015 Getify Solutions, Inc. All rights reserved. Printed in the United States of Ameri...
View in text
Excerpt 2
tence check if (typeof DEBUG !== "undefined") { console.log( "Debugging is starting" ); } This sort of check is useful even if you’re not dealing with user-...
View in text
Excerpt 3
back. In other words, in an almost poetic sense, you can go from finite to infinite but not from infinite back to finite. It’s almost philosophical to ask: “...
View in text
Excerpt 4
"abc" b.valueOf(); // 42 c.valueOf(); // true Unboxing | 43 As you can see with c in this example, empty slots in an array can happen after creation of the a...
View in text
Excerpt 5
eOf() and toString()—if it has a null value for its [[Proto type]], typically created with Object.create(null). See the this & Object Prototypes title in thi...
View in text
Excerpt 6
value to a string to perform the parse on is quite sensible. If you pass in garbage, and you get garbage back out, don’t blame the trash can—it just did its...
View in text
Excerpt 7
ng more work than ==, because it has to also check the type. In the second explana‐ Loose Equals Versus Strict Equals | 99 The != loose not-equality operatio...
View in text
Excerpt 8
r? The comparison " " == NaN would of course fail, but it’s unclear that we’d have really fixed any of the underlying concerns. The chances that a real-world...
View in text
Tags
AI categories
JavaScriptProgramming LanguageCode
ISBN: 1491904194
Publisher: O'Reilly Media
Publish Year: 2015
Language: English
Pages: 195
File Format: PDF
File Size: 10.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…