Iterators, Iterables, the for-of Loop, and Iterable Spread Syntax 131
Generator Functions 146
Old Habits to New 163
Chapter 7: Destructuring 165
Overview 165
Basic Object Destructuring 166
Basic Array (and Iterable) Destructuring 169
Defaults 170
Rest Syntax in Destructuring Patterns 172
Using Different Names 173
Computed Property Names 174
Nested Destructuring 174
Parameter Destructuring 175
Destructuring in Loops 178
Old Habits to New 179
Chapter 8: Promises 181
Why Promises? 182
Promise Fundamentals 182
Using an Existing Promise 186
Adding Handlers to Already Settled Promises 201
Creating Promises 202
Other Promise Utility Methods 207
Promise Patterns 210
Handle Errors or Return the Promise 210
Promises in Series 211
Promises in Parallel 213
Promise Subclasses 218
Old Habits to New 219
Chapter 9: Asynchronous Functions, Iterators, and Generators 221
async Functions 222
async Iterators, Iterables, and Generators 232
for-await-of 238
Old Habits to New 238
Chapter 10: Templates, Tag Functions, and New String Features 241
Template Literals 241
Improved Unicode Support 250
Iteration 255
New String Methods 256
Updates to the match, split, search, and replace Methods 259
Old Habits to New 260
Chapter 11: New Array Features, Typed Arrays 263
New Array Methods 264
Iteration, Spread, Destructuring 276
Stable Array Sort 276
Typed Arrays 277
Old Habits to New 292
Chapter 12: Maps and Sets 293
Maps 293
Sets 300
WeakMaps 304
WeakSets 314
Old Habits to New 316
Chapter 13: Modules 319
Introduction to Modules 319
Module Fundamentals 320
Renaming Exports 331
Re-Exporting Exports from Another Module 332
Renaming Imports 333
Importing a Module’s Namespace Object 333
Exporting Another Module’s Namespace Object 334
Importing a Module Just for Side Effects 335
Import and Export Entries 335
Imports are Live and Read-Only 338
Module Instances are Realm-Specific 340
How Modules are Loaded 341
Import/Export Syntax Review 348
Dynamic Import 350
Tree Shaking 357
Bundling 359
Import Metadata 360
Worker Modules 360
Old Habits to New 362
Chapter 14: Reflection—Reflect and Proxy 365
Reflect 365
Proxy 371
Old Habits to New 395
Chapter 15: Regular Expression Updates 397
The Flags Property 398
New Flags 398
Named Capture Groups 400
Lookbehind Assertions 405
Unicode Features 408
Old Habits to New 413
Chapter 16: Shared Memory 417
Introduction 417
Here There Be Dragons! 418
Browser Support 418
Shared Memory Basics 420
Memory is Shared, Not Objects 426
Race Conditions, Out-of-Order Stores, Stale Values, Tearing, and More 427
The Atomics Object 429
Shared Memory Example 434
Here There Be Dragons! (Again) 455
Old Habits to New 460
Chapter 17: Miscellany 461
BigInt 462
New Integer Literals 465
New Math Methods 467
Exponentiation Operator (**) 468
Date.prototype.toString Change 470
Function.prototype.toString Change 471
Number Additions 471
Symbol.isConcatSpreadable 474
Various Syntax Tweaks 475
Various Standard Library / Global Additions 479
Annex B: Browser-Only Features 482
Tail Call Optimization 488
Old Habits to New 491
Chapter 18: Upcoming Class Features 493
Public and Private Class Fields, Methods, and Accessors 493
Old Habits to New 514
Chapter 19: A Look Ahead . . .517
Top-Level await 518
WeakRefs and Cleanup Callbacks 525
RegExp Match Indices 533
String.prototype.replaceAll 535
Atomics asyncWait 535
Various Syntax Tweaks 536
Legacy Deprecated RegExp Features 537
Thank You for Reading! 538
Appendix: Fantastic Features and Where to Find Them 539
Index 557
JavaScript is a rapidly changing language and it can be challenging to keep up with all the new toys being added. JavaScript: The New Toys explores the newest features of the world's most popular programming language while also showing readers how to track what's coming next. After setting the stage by covering who manages the process of improving JavaScript, how new features get introduced, terminology, and a high-level overview of new features, it details each new or updated item in depth, with example uses, possible pitfalls, and expert recommendations for updating old habits in light of new features.
About the Author About the author
T.J. Crowder is a software engineer with 30 years of experience, including over 15 years of professional work in JavaScript. He runs Farsight Software, a software contracting and product company. He's often found helping people on Stack Overflow, where he's a top 10 all-time contributor and the top JavaScript contributor. When not working or writing, he…no, sorry, he's always working or writing – or spending time with his wonderful, supportive wife and fantastic son.