copyright....2
welcome....3
brief contents....5
1 When a hello isn’t hello....6
1.1 Setting the stage....7
1.2 But why?....13
1.3 Getting started....14
1.3.1 Scheduling?....15
1.3.2 Tasks and queues....17
1.3.3 Language, implementation, and host defined behavior....19
1.4 What you’ll need....20
1.5 Summary....21
2 Strings....22
2.1 What is a string?....22
2.1.1 Let’s talk about encodings....25
2.1.2 Unicode, UTF-32, UTF-16, and UTF-8....27
2.1.3 DOMString vs. ByteString vs. USVString....40
2.1.4 So, about those “file not found” errors…....43
2.2 How V8 Implements Strings....46
2.2.1 Setting the stage: pathologically bad template generation....47
2.2.2 String memory....54
2.2.3 V8’s multiple string types....56
2.3 Summary....70
3 Numbers....71
3.2 What is a number....72
3.2.1 How numbers are encoded using bytes....72
3.3 What is a BigInt....88
3.3.1 Bigint limitations....89
3.3.2 BigInts vs. Numbers....91
3.4 Introducing Decimals....92
3.5 How V8 implements numbers....93
3.5.1 SMI: The small integer fast path....94
3.5.2 The number representation hierarchy....94
3.5.3 Performance optimization strategies....96
3.6 Summary....100
4 Primitives, Coercion, and Equality....102
4.1 JavaScript’s two kinds of nothing....104
4.2 Booleans and Truthiness....106
4.2.1 Falsy vs. Truthy....106
4.2.2 Boolean operators and short-circuit logic....109
4.3 Symbols....111
4.3.1 How symbols differ from other primitives....112
4.3.2 The Global Symbol Registry....113
4.3.3 Memory considerations....114
4.4 Type coercion....114
4.4.1 The coercion problem in practice....115
4.4.2 When JavaScript coerces types....116
4.4.3 The three essential conversions....119
4.4.4 The performance cost....122
4.4.5 The specifications conversion operations....124
4.5 Type comparisons....125
4.5.1 Loose equality vs Strict equality....126
4.5.2 The comparison operators....126
4.6 Summary....127
5 Objects....128
5.1 What are objects?....129
5.2 Properties....130
5.3 Prototypical inheritance: the filing cabinet family tree....142
5.4 The mystery of this: context and identity....152
5.4.1 Functions are just objects....156
5.4.2 Modern Javascript: classes....156
5.5 Arrays....163
5.6 Proxy objects....165
5.7 Converting objects to strings and symbol properties....168
5.7.1 How V8 implements objects....172
5.8 Hidden classes and shapes: the secret object blueprint....173
5.9 Inline caches: V8's speed boost system....178
5.10 Summary....181
7 Errors....183
7.1 The dual, and often opposing purpose of errors....184
7.2 What are JavaScript errors?....185
7.2.1 The native errors....186
7.2.2 Modern error types....187
7.2.3 The error cause chain....191
7.3 Node.js errors....192
7.4 The error stack....194
7.4.1 Stacks are expensive....196
7.4.2 Mitigating the costs....198
7.5 Error propagation and control flow....199
7.6 Summary....209
Explore the inner workings of the world’s most popular programming language and enjoy the power and control that comes only from deep knowledge! In JavaScript in Depth, JavaScript and Node legend James M. Snell goes beyond the basic syntax and common implementations to expose the secrets of its engines, runtimes, and language design decisions.
Written by core Node.js and TC-39 committee contributor James M. Snell, JavaScript in Depth teaches you what’s really happening when JavaScript handles asynchronous tasks, manages memory, or interacts with system APIs. This interesting and entertaining book is filled with insights that you reason better about your code, your tools, and your runtime environments.
JavaScript in Depth isn’t a “how-to” guide—it’s a “how it works” guide. In it, you’ll find detailed code samples, in-depth technical breakdowns, and real examples drawn from production environments, all connecting JS theory to everyday development. You’ll see how JS engines execute code and interact with system APIs, how runtimes power your applications, and why JavaScript behaves the way it does. Whether you read it cover-to-cover or dip in as an easy reference, this book will help you refresh obscure topics, troubleshoot complex bugs, and make best use of AI-generated code snippets.
This book is written to turn JavaScript beginners into JavaScript veterans, with a deep understanding of the language.