Practical Modern JavaScript

Book description

To get the most out of modern JavaScript, you need learn the latest features of its parent specification, ECMAScript 6 (ES6). This book provides a highly practical look at ES6, without getting lost in the specification or its implementation details. Armed with practical examples, author Nicolas Bevacqua shows you new ways to deal with asynchronous flow control, declare objects or functions, and create proxies or unique sets, among many other features.

The first title in Bevacqua’s Modular JavaScript series, Practical Modern JavaScript prepares JavaScript and Node.js developers for applied lessons in modular design, testing, and deployment in subsequent books.

This book explains:

  • How JavaScript and its standards development process have evolved
  • Essential ES6 changes, including arrow functions, destructuring, let and const
  • Class syntax for declaring object prototypes, and the new Symbol primitive
  • How to handle flow control with Promises, iterators, generators, and async functions
  • ES6 collection built-in types for creating object maps and unique sets
  • How and when to use the new Proxy and Reflect built-ins
  • Changes to Array, Math, numbers, strings, Unicode, and regular expressions, and other improvements since ES5

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Who Should Read This Book
    2. Why Modern JavaScript?
    3. How Is This Book Organized?
    4. Conventions Used in This Book
    5. O’Reilly Safari
    6. How to Contact Us
    7. Acknowledgments
  3. ECMAScript and the Future of JavaScript
    1. 1.1 A Brief History of JavaScript Standards
    2. 1.2 ECMAScript as a Rolling Standard
    3. 1.3 Browser Support and Complementary Tooling
      1. 1.3.1 Introduction to the Babel Transpiler
      2. 1.3.2 Code Quality and Consistency with ESLint
    4. 1.4 Feature Themes in ES6
    5. 1.5 Future of JavaScript
  4. ES6 Essentials
    1. 2.1 Object Literals
      1. 2.1.1 Property Value Shorthands
      2. 2.1.2 Computed Property Names
      3. 2.1.3 Method Definitions
    2. 2.2 Arrow Functions
      1. 2.2.1 Lexical Scoping
      2. 2.2.2 Arrow Function Flavors
      3. 2.2.3 Merits and Use Cases
    3. 2.3 Assignment Destructuring
      1. 2.3.1 Destructuring Objects
      2. 2.3.2 Destructuring Arrays
      3. 2.3.3 Function Parameter Defaults
      4. 2.3.4 Function Parameter Destructuring
      5. 2.3.5 Use Cases for Destructuring
    4. 2.4 Rest Parameter and Spread Operator
      1. 2.4.1 Rest Parameters
      2. 2.4.2 Spread Operator
    5. 2.5 Template Literals
      1. 2.5.1 String Interpolation
      2. 2.5.2 Multiline Template Literals
      3. 2.5.3 Tagged Templates
    6. 2.6 let and const Statements
      1. 2.6.1 Block Scoping and let Statements
      2. 2.6.2 Temporal Dead Zone
      3. 2.6.3 Const Statements
      4. 2.6.4 Merits of const and let
  5. Classes, Symbols, Objects, and Decorators
    1. 3.1 Classes
      1. 3.1.1 Class Fundamentals
      2. 3.1.2 Properties and Methods in Classes
      3. 3.1.3 Extending JavaScript Classes
    2. 3.2 Symbols
      1. 3.2.1 Local Symbols
      2. 3.2.2 Practical Use Cases for Symbols
      3. 3.2.3 Global Symbol Registry
      4. 3.2.4 Well-Known Symbols
    3. 3.3 Object Built-in Improvements
      1. 3.3.1 Extending Objects with Object.assign
      2. 3.3.2 Comparing Objects with Object.is
      3. 3.3.3 Object.setPrototypeOf
    4. 3.4 Decorators
      1. 3.4.1 A Primer on JavaScript Decorators
      2. 3.4.2 Stacking Decorators and a Warning About Immutability
      3. 3.4.3 Use Case By Example: Attributes in C#
      4. 3.4.4 Marking Properties in JavaScript
  6. Iteration and Flow Control
    1. 4.1 Promises
      1. 4.1.1 Getting Started with Promises
      2. 4.1.2 Promise Continuation and Chaining
      3. 4.1.3 Creating a Promise from Scratch
      4. 4.1.4 Promise States and Fates
      5. 4.1.5 Promise#finally Proposal
      6. 4.1.6 Leveraging Promise.all and Promise.race
    2. 4.2 Iterator Protocol and Iterable Protocol
      1. 4.2.1 Understanding Iteration Principles
      2. 4.2.2 Infinite Sequences
      3. 4.2.3 Iterating Object Maps as Key/Value Pairs
      4. 4.2.4 Building Versatility Into Iterating a Playlist
    3. 4.3 Generator Functions and Generator Objects
      1. 4.3.1 Generator Fundamentals
      2. 4.3.2 Iterating over Generators by Hand
      3. 4.3.3 Mixing Generators into Iterables
      4. 4.3.4 Tree Traversal Using Generators
      5. 4.3.5 Consuming Generator Functions for Flexibility
      6. 4.3.6 Dealing with Asynchronous Flows
      7. 4.3.7 Throwing Errors at a Generator
      8. 4.3.8 Returning on Behalf of a Generator
      9. 4.3.9 Asynchronous I/O Using Generators
    4. 4.4 Async Functions
      1. 4.4.1 Flavors of Async Code
      2. 4.4.2 Using async/await
      3. 4.4.3 Concurrent Async Flows
      4. 4.4.4 Error Handling
      5. 4.4.5 Understanding Async Function Internals
    5. 4.5 Asynchronous Iteration
      1. 4.5.1 Async Iterators
      2. 4.5.2 Async Generators
  7. Leveraging ECMAScript Collections
    1. 5.1 Using ES6 Maps
      1. 5.1.1 First Look into ES6 Maps
      2. 5.1.2 Hash-Maps and the DOM
    2. 5.2 Understanding and Using WeakMap
      1. 5.2.1 Is WeakMap a Worse Map?
    3. 5.3 Sets in ES6
    4. 5.4 ES6 WeakSets
  8. Managing Property Access with Proxies
    1. 6.1 Getting Started with Proxy
      1. 6.1.1 Trapping get Accessors
      2. 6.1.2 Trapping set Accessors
      3. 6.1.3 Schema Validation with Proxies
    2. 6.2 Revocable Proxies
    3. 6.3 Proxy Trap Handlers
      1. 6.3.1 has Trap
      2. 6.3.2 deleteProperty Trap
      3. 6.3.3 defineProperty Trap
      4. 6.3.4 ownKeys Trap
    4. 6.4 Advanced Proxy Traps
      1. 6.4.1 getOwnPropertyDescriptor Trap
      2. 6.4.2 apply Trap
      3. 6.4.3 construct Trap
      4. 6.4.4 getPrototypeOf Trap
      5. 6.4.5 setPrototypeOf Trap
      6. 6.4.6 preventExtensions Trap
      7. 6.4.7 isExtensible Trap
  9. Built-in Improvements in ES6
    1. 7.1 Numbers
      1. 7.1.1 Binary and Octal Literals
      2. 7.1.2 Number.isNaN
      3. 7.1.3 Number.isFinite
      4. 7.1.4 Number.parseInt
      5. 7.1.5 Number.parseFloat
      6. 7.1.6 Number.isInteger
      7. 7.1.7 Number.EPSILON
      8. 7.1.8 Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER
      9. 7.1.9 Number.isSafeInteger
    2. 7.2 Math
      1. 7.2.1 Math.sign
      2. 7.2.2 Math.trunc
      3. 7.2.3 Math.cbrt
      4. 7.2.4 Math.expm1
      5. 7.2.5 Math.log1p
      6. 7.2.6 Math.log10
      7. 7.2.7 Math.log2
      8. 7.2.8 Trigonometric Functions
      9. 7.2.9 Math.hypot
      10. 7.2.10 Bitwise Computation Helpers
    3. 7.3 Strings and Unicode
      1. 7.3.1 String#startsWith
      2. 7.3.2 String#endsWith
      3. 7.3.3 String#includes
      4. 7.3.4 String#repeat
      5. 7.3.5 String Padding and Trimming
      6. 7.3.6 Unicode
      7. 7.3.7 String.prototype[Symbol.iterator]
      8. 7.3.8 A Proposal to Split Grapheme Segments
      9. 7.3.9 String#codePointAt
      10. 7.3.10 String.fromCodePoint
      11. 7.3.11 Unicode-Aware String Reversal
      12. 7.3.12 String#normalize
    4. 7.4 Regular Expressions
      1. 7.4.1 Sticky Matching Flag /y
      2. 7.4.2 Unicode Flag /u
      3. 7.4.3 Named Capture Groups
      4. 7.4.4 Unicode Property Escapes
      5. 7.4.5 Lookbehind Assertions
      6. 7.4.6 A New /s “dotAll” Flag
      7. 7.4.7 String#matchAll
    5. 7.5 Array
      1. 7.5.1 Array.from
      2. 7.5.2 Array.of
      3. 7.5.3 Array#copyWithin
      4. 7.5.4 Array#fill
      5. 7.5.5 Array#find and Array#findIndex
      6. 7.5.6 Array#keys
      7. 7.5.7 Array#values
      8. 7.5.8 Array#entries
      9. 7.5.9 Array.prototype[Symbol.iterator]
  10. JavaScript Modules
    1. 8.1 CommonJS
    2. 8.2 JavaScript Modules
      1. 8.2.1 Strict Mode
      2. 8.2.2 export Statements
      3. 8.2.3 import Statements
      4. 8.2.4 Dynamic import()
    3. 8.3 Practical Considerations for ES Modules
  11. Practical Considerations
    1. 9.1 Variable Declarations
    2. 9.2 Template Literals
    3. 9.3 Shorthand Notation and Object Destructuring
    4. 9.4 Rest and Spread
    5. 9.5 Savoring Function Flavors
    6. 9.6 Classes and Proxies
    7. 9.7 Asynchronous Code Flows
    8. 9.8 Complexity Creep, Abstractions, and Conventions
  12. Index

Product information

  • Title: Practical Modern JavaScript
  • Author(s): Nicolas Bevacqua
  • Release date: June 2017
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491943540