This book makes JavaScript less challenging to learn for newcomers, by offering a modern view that is as consistent as possible.
Highlights:
- Get started quickly, by initially focusing on modern features.
- Test-driven exercises and quizzes available for most chapters (sold separately).
- Covers all essential features of JavaScript, up to and including ES2019.
- Optional advanced sections let you dig deeper.
No prior knowledge of JavaScript is required, but you should know how to program.
Author(s): Dr. Axel Rauschmayer
Edition: ECMAScript 2021 edition
Publisher: Independently published
Year: 2021
Language: English
Commentary: True PDF
Pages: 526
I Background
Before you buy the book
About the content
Previewing and buying this book
About the author
Acknowledgements
FAQ: book and supplementary material
How to read this book
I own a digital version
I own the print version
Notations and conventions
Why JavaScript? (bonus)
The cons of JavaScript
The pros of JavaScript
Pro and con of JavaScript: innovation
The nature of JavaScript (bonus)
JavaScript's influences
The nature of JavaScript
Tips for getting started with JavaScript
History and evolution of JavaScript
How JavaScript was created
Standardizing JavaScript
Timeline of ECMAScript versions
Ecma Technical Committee 39 (TC39)
The TC39 process
FAQ: TC39 process
Evolving JavaScript: Don't break the web
New JavaScript features
New in ECMAScript 2021
New in ECMAScript 2020
New in ECMAScript 2019
New in ECMAScript 2018
New in ECMAScript 2017
New in ECMAScript 2016
Source of this chapter
FAQ: JavaScript
What are good references for JavaScript?
How do I find out what JavaScript features are supported where?
Where can I look up what features are planned for JavaScript?
Why does JavaScript fail silently so often?
Why can't we clean up JavaScript, by removing quirks and outdated features?
How can I quickly try out a piece of JavaScript code?
II First steps
Using JavaScript: the big picture
What are you learning in this book?
The structure of browsers and Node.js
JavaScript references
Further reading
Syntax
An overview of JavaScript's syntax
(Advanced)
Identifiers
Statement vs. expression
Ambiguous syntax
Semicolons
Automatic semicolon insertion (ASI)
Semicolons: best practices
Strict mode vs. sloppy mode
Consoles: interactive JavaScript command lines
Trying out JavaScript code
The console.* API: printing data and more
Assertion API
Assertions in software development
How assertions are used in this book
Normal comparison vs. deep comparison
Quick reference: module assert
Getting started with quizzes and exercises
Quizzes
Exercises
Unit tests in JavaScript
III Variables and values
Variables and assignment
let
const
Deciding between const and let
The scope of a variable
(Advanced)
Terminology: static vs. dynamic
Global variables and the global object
Declarations: scope and activation
Closures
Values
What's a type?
JavaScript's type hierarchy
The types of the language specification
Primitive values vs. objects
The operators typeof and instanceof: what's the type of a value?
Classes and constructor functions
Converting between types
Operators
Making sense of operators
The plus operator (+)
Assignment operators
Equality: == vs. ===
Ordering operators
Various other operators
IV Primitive values
The non-values undefined and null
undefined vs. null
Occurrences of undefined and null
Checking for undefined or null
The nullish coalescing operator (??) for default values [ES2020]
undefined and null don't have properties
The history of undefined and null
Booleans
Converting to boolean
Falsy and truthy values
Truthiness-based existence checks
Conditional operator (? :)
Binary logical operators: And (x && y), Or (x || y)
Logical Not (!)
Numbers
Numbers are used for both floating point numbers and integers
Number literals
Arithmetic operators
Converting to number
Error values
The precision of numbers: careful with decimal fractions
(Advanced)
Background: floating point precision
Integer numbers in JavaScript
Bitwise operators
Quick reference: numbers
Math
Data properties
Exponents, roots, logarithms
Rounding
Trigonometric Functions
Various other functions
Sources
Bigints – arbitrary-precision integers [ES2020] (advanced)
Why bigints?
Bigints
Bigint literals
Reusing number operators for bigints (overloading)
The wrapper constructor BigInt
Coercing bigints to other primitive types
TypedArrays and DataView operations for 64-bit values
Bigints and JSON
FAQ: Bigints
Unicode – a brief introduction (advanced)
Code points vs. code units
Encodings used in web development: UTF-16 and UTF-8
Grapheme clusters – the real characters
Strings
Plain string literals
Accessing characters and code points
String concatenation via +
Converting to string
Comparing strings
Atoms of text: Unicode characters, JavaScript characters, grapheme clusters
Quick reference: Strings
Using template literals and tagged templates
Disambiguation: ``template''
Template literals
Tagged templates
Examples of tagged templates (as provided via libraries)
Raw string literals
(Advanced)
Multiline template literals and indentation
Simple templating via template literals
Symbols
Symbols are primitives that are also like objects
The descriptions of symbols
Use cases for symbols
Publicly known symbols
Converting symbols
V Control flow and data flow
Control flow statements
Controlling loops: break and continue
Conditions of control flow statements
if statements [ES1]
switch statements [ES3]
while loops [ES1]
do-while loops [ES3]
for loops [ES1]
for-of loops [ES6]
for-await-of loops [ES2018]
for-in loops (avoid) [ES1]
Recomendations for looping
Exception handling
Motivation: throwing and catching exceptions
throw
The try statement
Error classes
Callable values
Kinds of functions
Ordinary functions
Specialized functions
Summary: kinds of callable values
Returning values from functions and methods
Parameter handling
Methods of functions: .call(), .apply(), .bind()
Evaluating code dynamically: eval(), new Function() (advanced)
eval()
new Function()
Recommendations
VI Modularity
Modules
Overview: syntax of ECMAScript modules
JavaScript source code formats
Before we had modules, we had scripts
Module systems created prior to ES6
ECMAScript modules
Named exports and imports
Default exports and imports
More details on exporting and importing
npm packages
Naming modules
Module specifiers
Loading modules dynamically via import() [ES2020]
import.meta – metadata for the current module [ES2020]
Polyfills: emulating native web platform features (advanced)
Single objects
What is an object?
Objects as records
Spreading into object literals (...) [ES2018]
Methods and the special variable this
Optional chaining for property accesses and method calls [ES2020] (advanced)
Objects as dictionaries (advanced)
Standard methods (advanced)
Advanced topics
Prototype chains and classes
Prototype chains
Classes
Private data for classes
Subclassing
FAQ: objects
VII Collections
Synchronous iteration
What is synchronous iteration about?
Core iteration constructs: iterables and iterators
Iterating manually
Iteration in practice
Quick reference: synchronous iteration
Arrays (Array)
The two roles of Arrays in JavaScript
Basic Array operations
for-of and Arrays [ES6]
Array-like objects
Converting iterable and Array-like values to Arrays
Creating and filling Arrays with arbitrary lengths
Multidimensional Arrays
More Array features (advanced)
Adding and removing elements (destructively and non-destructively)
Methods: iteration and transformation (.find(), .map(), .filter(), etc.)
.sort(): sorting Arrays
Quick reference: Array
Typed Arrays: handling binary data (advanced)
The basics of the API
Element types
More information on Typed Arrays
Quick references: indices vs. offsets
Quick reference: ArrayBuffers
Quick reference: Typed Arrays
Quick reference: DataViews
Maps (Map)
Using Maps
Example: Counting characters
A few more details about the keys of Maps (advanced)
Missing Map operations
Quick reference: Map
FAQ: Maps
WeakMaps (WeakMap) (advanced)
WeakMaps are black boxes
The keys of a WeakMap are weakly held
Examples
WeakMap API
Sets (Set)
Using Sets
Examples of using Sets
What Set elements are considered equal?
Missing Set operations
Quick reference: Set
FAQ: Sets
WeakSets (WeakSet) (advanced)
Example: Marking objects as safe to use with a method
WeakSet API
Destructuring
A first taste of destructuring
Constructing vs. extracting
Where can we destructure?
Object-destructuring
Array-destructuring
Examples of destructuring
What happens if a pattern part does not match anything?
What values can't be destructured?
(Advanced)
Default values
Parameter definitions are similar to destructuring
Nested destructuring
Synchronous generators (advanced)
What are synchronous generators?
Calling generators from generators (advanced)
Background: external iteration vs. internal iteration
Use case for generators: reusing traversals
Advanced features of generators
VIII Asynchronicity
Asynchronous programming in JavaScript
A roadmap for asynchronous programming in JavaScript
The call stack
The event loop
How to avoid blocking the JavaScript process
Patterns for delivering asynchronous results
Asynchronous code: the downsides
Resources
Promises for asynchronous programming [ES6]
The basics of using Promises
Examples
Error handling: don't mix rejections and exceptions
Promise-based functions start synchronously, settle asynchronously
Promise combinator functions: working with Arrays of Promises
Concurrency and Promise.all() (advanced)
Tips for chaining Promises
Quick reference: Promise combinator functions
Async functions
Async functions: the basics
Returning from async functions
await: working with Promises
(Advanced)
Immediately invoked async arrow functions
Concurrency and await
Tips for using async functions
Asynchronous iteration
Basic asynchronous iteration
Asynchronous generators
Async iteration over Node.js streams
IX More standard library
Regular expressions (RegExp)
Creating regular expressions
Syntax
Flags
Properties of regular expression objects
Methods for working with regular expressions
The flags /g and /y, and the property .lastIndex (advanced)
Techniques for working with regular expressions
Dates (Date)
Best practice: avoid the built-in Date
Time standards
Background: date time formats (ISO)
Time values
Creating Dates
Getters and setters
Converting Dates to strings
Creating and parsing JSON (JSON)
The discovery and standardization of JSON
JSON syntax
Using the JSON API
Customizing stringification and parsing (advanced)
FAQ
X Miscellaneous topics
Next steps: overview of web development (bonus)
Tips against feeling overwhelmed
Things worth learning for web development
Example: tool-based JavaScript workflow
An overview of JavaScript tools
Tools not related to JavaScript
XI Appendices
Index