What you need to know about this book
Table of contents
Please support this book: buy it (PDF, EPUB, MOBI) or donate
(Ad, please don’t block.)

What you need to know about this book

This book is about ECMAScript 6 (whose official name is ECMAScript 2015), a new version of JavaScript.

Audience: JavaScript programmers

In order to understand this book, you should already know JavaScript. If you don’t: my other book “Speaking JavaScript” is free online and teaches programmers all of JavaScript (up to and including ECMAScript 5).

Why should I read this book?

How to read this book

This book covers ES6 with three levels of detail:

Other things to know:

Sources of this book

I started writing this book long before there were implementations of ES6 features, which required quite a bit of research. Essential sources were:


Strict mode versus sloppy mode

ECMAScript 5 introduced language modes: Strict mode makes JavaScript a cleaner language by changing its semantics, performing more checks and throwing more exceptions. Consult Sect. “Strict Mode” in “Speaking JavaScript” for more information. The legacy/default mode is called non-strict mode or sloppy mode.

Strict mode is switched on via the following line (which does nothing in ECMAScript versions before ES5):

'use strict';

If you put this line at the beginning of a file, all code in it is in strict mode. If you make this line the first line of a function, only that function is in strict mode.

Using a directive to switch on strict mode is not very user friendly and was one of the reasons why strict mode was not nearly as popular in ES5 as it should be. However, ES6 modules and classes are implicitly in strict mode. Given that most ES6 code will live in modules, strict mode becomes the de-facto default for ES6.


The term protocol has various meanings in computing. In the context of programming languages and API design, I’m using it as follows:

A protocol defines interfaces (signatures for methods and/or functions) and rules for using them.

The idea is to specify how a service is to be performed. Then anyone can perform the service and anyone can request it and they are guaranteed to work together well.

Note that the definition given here is different from viewing a protocol as an interface (as, for example, Objective C does), because this definition includes rules.

Receiver (of a method call)

Given a method call obj.m(···), obj is the receiver of the method call and accessible via this inside the method.

Signature of a function (or a method)

The (type) signature of a function describes how the function is to be called, what its inputs and its output are. I’m using the syntax established by Microsoft TypeScript and Facebook Flow in this book. An example of a signature:

parseInt(string : string, radix? : number) : number

You can see that parseInt() expects a string and a number and returns a number. If the type of a parameter is clear, I often omit the type annotation.

Internal slots

The ES6 language specification uses internal slots to store internal data. In the spec, internal slots are accessed as if they were properties whose names are in square brackets:


Two things differentiate them from properties:

How exactly internal slots are stored is left unspecified. Some may not even exist in actual JavaScript implementations.

Bindings and environments

The ECMAScript spec uses a data structure called environment to store the variables of a scope. An environment is basically a dictionary that maps variable names to values. A binding is an entry in an environment, storage space for a variable.

Destructive operations

Destructive operations (methods, functions) modify their parameters or their receivers. For example, push() modifies its receiver arr:

> const arr = ['a', 'b'];
> arr.push('c')
> arr
[ 'a', 'b', 'c' ]

In contrast, concat() creates a new Array and does not change its receiver arr:

> const arr = ['a', 'b'];
> arr.concat(['c'])
[ 'a', 'b', 'c' ]
> arr
[ 'a', 'b' ]


Documenting classes

The API of a class C is usually documented as follows:


In English, I capitalize JavaScript terms as follows:

Demo code on GitHub

Several repositories on GitHub contain code shown in this book:


Sidebars are boxes of text marked with icons. They complement the normal content.


Occasionally, I refer to (publicly available) external material via footnotes. Two sources are marked with a prefix in square brackets:

Next: Foreword