JavaScript for impatient programmers

3,634 760 7MB

English Pages [872] Year 2019

Report DMCA / Copyright

DOWNLOAD FILE

JavaScript for impatient programmers

Table of contents :
JavaScript for impatient programmers
JavaScript for impatient programmers
About this book (ES2019 edition)
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 edition
I own the print edition
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
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?
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
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
Further reading
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
The non-values undefined and null
undefined vs. null
Occurrences of undefined and null
Checking for undefined or null
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
JavaScript only has floating point numbers
Number literals
Arithmetic operators
Converting to number
Error values
Error value: NaN
Error value: Infinity
The precision of numbers: careful with decimal fractions
(Advanced)
Background: floating point precision
Integers in JavaScript
Bitwise operators
Quick reference: numbers
Math
Data properties
Exponents, roots, logarithms
Rounding
Trigonometric Functions
Various other functions
Sources
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
Raw string literals
(Advanced)
Multiline template literals and indentation
Simple templating via template literals
Symbols
Use cases for symbols
Publicly known symbols
Converting symbols
Control flow statements
Conditions of control flow statements
Controlling loops: break and continue
if statements
switch statements
while loops
do-while loops
for loops
for-of loops
for-await-of loops
for-in loops (avoid)
Exception handling
Motivation: throwing and catching exceptions
throw
The try statement
Error classes
Callable values
Kinds of functions
Ordinary functions
Specialized functions
More kinds of functions and methods
Returning values from functions and methods
Parameter handling
Dynamically evaluating code: eval(), new Function() (advanced)
Environments: under the hood of variables (bonus)
Environment: data structure for managing variables
Recursion via environments
Nested scopes via environments
Closures and environments
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()
Preview: import.meta.url
Polyfills: emulating native web platform features (advanced)
Single objects
What is an object?
Objects as records
Spreading into object literals (...)
Methods
Objects as dictionaries (advanced)
Standard methods (advanced)
Advanced topics
Prototype chains and classes
Prototype chains
Classes
Private data for classes
Subclassing
FAQ: objects
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
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)
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)
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
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
The basics of using Promises
Examples
Error handling: don’t mix rejections and exceptions
Promise-based functions start synchronously, settle asynchronously
Promise.all(): concurrency and Arrays of Promises
Tips for chaining Promises
Advanced topics
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
Regular expressions (RegExp)
Creating regular expressions
Syntax
Flags
Properties of regular expression objects
Methods for working with regular expressions
Flag /g and its pitfalls
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
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
Index

Polecaj historie