Exploring
Exploring
Axel Rauschmayer
This book is for sale at http://leanpub.com/exploring-es2016-es2017
This version was published on 2016-05-25
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools
and many iterations to get reader feedback, pivot until you have the right book and build
traction once you do.
2016 Axel Rauschmayer
Contents
What you need to know about this book . . . . . . . . . . . . . . . . . . . . . . . . . .
What is in this book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
i
i
i
ii
Background
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
2
2
2
2
3
4
5
6
6
II
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
8
8
ECMAScript 2016
III
ECMAScript 2017
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
9
9
9
10
10
. . . . . . . . . . . . . . . . . . . . . . . . . . . 11
12
12
12
CONTENTS
5.2
5.3
5.1.2 Object.values() . . . . . . . . . . . .
Object.entries() . . . . . . . . . . . . . .
5.2.1 Setting up Maps via Object.entries()
5.2.2 FAQ: Object.entries() . . . . . . . .
Object.values() . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
12
12
13
13
13
Support
Forum: The Exploring ES6 homepage links to a forum where you can discuss questions
and ideas related to this book.
Errata (typos, errors, etc.): On the Exploring ES6 homepage, there are links to a form
for submitting errata and to a list with submitted errata.
http://speakingjs.com/es5/
http://exploringjs.com/es6/
http://www.2ality.com/2016/02/ecmascript-2017.html
http://exploringjs.com/#forum
http://exploringjs.com/#errata
ii
I Background
Whats required? The spec text must be complete. Designated reviewers (appointed by TC39,
not by the champion) and the ECMAScript spec editor must sign off on the spec text. There must
be at least two spec-compliant implementations (which dont have to be enabled by default).
Whats next? Henceforth, changes should only be made in response to critical issues raised by
the implementations and their use.
1.2.2.5 Stage 4: finished
What is it? The proposal is ready to be included in the standard.
Whats required? The following things are needed before a proposal can reach this stage:
Test 262 acceptance tests (roughly, unit tests for the language feature, written in JavaScript).
Two spec-compliant shipping implementations that pass the tests.
Significant practical experience with the implementations.
The ECMAScript spec editor must sign off on the spec text.
Whats next? The proposal will be included in the ECMAScript specification as soon as possible.
When the spec goes through its yearly ratification as a standard, the proposal is ratified as part
of it.
II ECMAScript 2016
3.1 Overview
1
2
> 6 ** 2
36
x ** y
Math.pow(x, y)
Examples:
1
2
3
4
5
let squared = 3 ** 2; // 9
let num = 3;
num **= 2;
console.log(num); // 9
Further reading:
Exponentiation Operator (Rick Waldron)
https://github.com/rwaldron/exponentiation-operator
4. ES2016 feature:
Array.prototype.includes
This chapter describes the ECMAScript proposal Array.prototype.includes by Domenic
Denicola and Rick Waldron.
4.1 Overview
1
2
3
4
It returns true if value is an element of its receiver (this) and false, otherwise:
1
2
3
4
1
2
arr.includes(x)
arr.indexOf(x) >= 0
The main difference is that includes() finds NaN, whereas indexOf() doesnt:
1
2
3
4
10
> [NaN].includes(NaN)
true
> [NaN].indexOf(NaN)
-1
includes does not distinguish between +0 and -0 (which is how almost all of JavaScript works):
1
2
> [-0].includes(+0)
true
11
5.1 Overview
5.1.1 Object.entries()
1
2
3
4
5
6
7
5.1.2 Object.values()
1
2
5.2 Object.entries()
This method has the following signature:
1
If a JavaScript data structure has keys and values then an entry is a key-value pair, encoded
as a 2-element Array. Object.entries(x) coerces x to an Object and returns the entries of its
enumerable own string-keyed properties, in an Array:
1
2
12
1
2
13
5.3 Object.values()
Object.values() has the following signature:
http://exploringjs.com/es6/ch_iteration.html#sec_plain-objects-not-iterable
14
It works much like Object.entries(), but, as its name suggests, it only returns the values of the
own enumerable string-keyed properties:
1
2