,Eloquent JavaScript
3rd edition
Marijn Haverbeke
,Copyright © 2018 by Marijn Haverbeke
This work is licensed under a Creative Commons attribution-noncommercial
license (http://creativecommons.org/licenses/by-nc/3.0/). All code in
the book may also be considered licensed under an MIT license (https:
//eloquentjavascript.net/code/LICENSE).
The illustrations are contributed by various artists: Cover and chap-
ter illustrations by Madalina Tantareanu. Pixel art in Chapters 7 and
16 by Antonio Perdomo Pastor. Regular expression diagrams in Chap-
ter 9 generated with regexper.com by Jeff Avallone. Village photograph
in Chapter 11 by Fabrice Creuzot. Game concept for Chapter 16 by
Thomas Palef.
The third edition of Eloquent JavaScript was made possible by 325
financial backers.
You can buy a print version of this book, with an extra bonus chapter in-
cluded, printed by No Starch Press at http://a-fwd.com/com=marijhaver-
20&asin-com=1593279507.
i
, Contents
Introduction 1
On programming . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Why language matters . . . . . . . . . . . . . . . . . . . . . . . 4
What is JavaScript? . . . . . . . . . . . . . . . . . . . . . . . . . 8
Code, and what to do with it . . . . . . . . . . . . . . . . . . . 11
Overview of this book . . . . . . . . . . . . . . . . . . . . . . . . 12
Typographic conventions . . . . . . . . . . . . . . . . . . . . . . 13
1 Values, Types, and Operators 15
Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Unary operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Boolean values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Empty values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Automatic type conversion . . . . . . . . . . . . . . . . . . . . . 28
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
ii
3rd edition
Marijn Haverbeke
,Copyright © 2018 by Marijn Haverbeke
This work is licensed under a Creative Commons attribution-noncommercial
license (http://creativecommons.org/licenses/by-nc/3.0/). All code in
the book may also be considered licensed under an MIT license (https:
//eloquentjavascript.net/code/LICENSE).
The illustrations are contributed by various artists: Cover and chap-
ter illustrations by Madalina Tantareanu. Pixel art in Chapters 7 and
16 by Antonio Perdomo Pastor. Regular expression diagrams in Chap-
ter 9 generated with regexper.com by Jeff Avallone. Village photograph
in Chapter 11 by Fabrice Creuzot. Game concept for Chapter 16 by
Thomas Palef.
The third edition of Eloquent JavaScript was made possible by 325
financial backers.
You can buy a print version of this book, with an extra bonus chapter in-
cluded, printed by No Starch Press at http://a-fwd.com/com=marijhaver-
20&asin-com=1593279507.
i
, Contents
Introduction 1
On programming . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Why language matters . . . . . . . . . . . . . . . . . . . . . . . 4
What is JavaScript? . . . . . . . . . . . . . . . . . . . . . . . . . 8
Code, and what to do with it . . . . . . . . . . . . . . . . . . . 11
Overview of this book . . . . . . . . . . . . . . . . . . . . . . . . 12
Typographic conventions . . . . . . . . . . . . . . . . . . . . . . 13
1 Values, Types, and Operators 15
Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Unary operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Boolean values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Empty values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Automatic type conversion . . . . . . . . . . . . . . . . . . . . . 28
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
ii