100% found this document useful (6 votes)
49 views

Complete Download Eloquent JavaScript 4th Edition Marijn Haverbeke PDF All Chapters

The document provides links to various eBooks available for download, including titles on JavaScript and engineering. It highlights the availability of instant digital products in multiple formats such as PDF, ePub, and MOBI. Additionally, it mentions the 4th edition of 'Eloquent JavaScript' by Marijn Haverbeke and includes licensing information for the book.

Uploaded by

sadeepizza0e
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
49 views

Complete Download Eloquent JavaScript 4th Edition Marijn Haverbeke PDF All Chapters

The document provides links to various eBooks available for download, including titles on JavaScript and engineering. It highlights the availability of instant digital products in multiple formats such as PDF, ePub, and MOBI. Additionally, it mentions the 4th edition of 'Eloquent JavaScript' by Marijn Haverbeke and includes licensing information for the book.

Uploaded by

sadeepizza0e
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Download the Full Ebook and Access More Features - ebookmass.

com

Eloquent JavaScript 4th Edition Marijn Haverbeke

https://ebookmass.com/product/eloquent-javascript-4th-
edition-marijn-haverbeke/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

JavaScript T. J. Crowder

https://ebookmass.com/product/javascript-t-j-crowder/

ebookmass.com

Javascript: Crash Course - The Complete Beginners Guide To


Learning JavaScript Programming In No Time! (Angularjs,
jQuery, JavaScript Visually) Nathaniel Hill
https://ebookmass.com/product/javascript-crash-course-the-complete-
beginners-guide-to-learning-javascript-programming-in-no-time-
angularjs-jquery-javascript-visually-nathaniel-hill/
ebookmass.com

JavaScript: A Beginner's Guide, Fifth Edition Pollock

https://ebookmass.com/product/javascript-a-beginners-guide-fifth-
edition-pollock/

ebookmass.com

Shigley's mechanical engineering design (11th Ed.) 11th


Edition Richard G. Budynas

https://ebookmass.com/product/shigleys-mechanical-engineering-
design-11th-ed-11th-edition-richard-g-budynas/

ebookmass.com
MYP Mathematics 2 (IB MYP SERIES) 1st Edition Torres-
Skoumal

https://ebookmass.com/product/myp-mathematics-2-ib-myp-series-1st-
edition-torres-skoumal/

ebookmass.com

The Environmental Impact of COVID-19 Deepak Rawtani

https://ebookmass.com/product/the-environmental-impact-of-
covid-19-deepak-rawtani/

ebookmass.com

Exploring Ibero-American Youth Cultures in the 21st


Century: Creativity, Resistance and Transgression in the
City 1st Edition Ricardo Campos
https://ebookmass.com/product/exploring-ibero-american-youth-cultures-
in-the-21st-century-creativity-resistance-and-transgression-in-the-
city-1st-edition-ricardo-campos/
ebookmass.com

Fitzgerald's Clinical Neuroanatomy and neuroscience 8th


Edition Estomih Mtui

https://ebookmass.com/product/fitzgeralds-clinical-neuroanatomy-and-
neuroscience-8th-edition-estomih-mtui/

ebookmass.com

Shi'ism Revisited: Ijtihad and Reformation in Contemporary


Times Liyakat Takim

https://ebookmass.com/product/shiism-revisited-ijtihad-and-
reformation-in-contemporary-times-liyakat-takim/

ebookmass.com
Electronic materials : principles and applied science
Poplavko

https://ebookmass.com/product/electronic-materials-principles-and-
applied-science-poplavko/

ebookmass.com
Eloquent JavaScript
4th edition

Marijn Haverbeke
Copyright © 2024 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 by Péchane Sumi-
e. Chapter illustrations by Madalina Tantareanu. Pixel art in Chapters 7 and
16 by Antonio Perdomo Pastor. Regular expression diagrams in Chapter 9
generated with regexper.com by Jeff Avallone. Village photograph in Chapter
11 by Fabrice Creuzot. Game concept for Chapter 16 by Thomas Palef.

You can buy a print version of this book, with an extra bonus chapter included,
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 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What is JavaScript? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Code, and what to do with it . . . . . . . . . . . . . . . . . . . . . . . 7
Overview of this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Typographic conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 8

1 Values, Types, and Operators 10


Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Unary operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Boolean values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Empty values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Automatic type conversion . . . . . . . . . . . . . . . . . . . . . . . . . 18
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2 Program Structure 21
Expressions and statements . . . . . . . . . . . . . . . . . . . . . . . . 21
Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Binding names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The console.log function . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Return values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Control flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
while and do loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Indenting Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Breaking Out of a Loop . . . . . . . . . . . . . . . . . . . . . . . . . . 32

ii
Updating bindings succinctly . . . . . . . . . . . . . . . . . . . . . . . 32
Dispatching on a value with switch . . . . . . . . . . . . . . . . . . . . 33
Capitalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

3 Functions 38
Defining a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Bindings and scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Nested scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Functions as values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Declaration notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Arrow functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The call stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Optional Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Growing functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Functions and side effects . . . . . . . . . . . . . . . . . . . . . . . . . 52
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4 Data Structures: Objects and Arrays 55


The weresquirrel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Data sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Mutability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
The lycanthrope’s log . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Computing correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Array loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
The final analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Further arrayology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Strings and their properties . . . . . . . . . . . . . . . . . . . . . . . . 69
Rest parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
The Math object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Destructuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Optional property access . . . . . . . . . . . . . . . . . . . . . . . . . . 74

iii
JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

5 Higher-Order Functions 79
Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Abstracting repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Higher-order functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Script data set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Filtering arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Transforming with map . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Summarizing with reduce . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Composability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Strings and character codes . . . . . . . . . . . . . . . . . . . . . . . . 88
Recognizing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

6 The Secret Life of Objects 93


Abstract Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Private Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Overriding derived properties . . . . . . . . . . . . . . . . . . . . . . . 99
Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Getters, setters, and statics . . . . . . . . . . . . . . . . . . . . . . . . 103
Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
The iterator interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
The instanceof operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

7 Project: A Robot 112


Meadowfield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
The task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Persistent data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

iv
The mail truck’s route . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Pathfinding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

8 Bugs and Errors 123


Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Strict mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Error propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Cleaning up after exceptions . . . . . . . . . . . . . . . . . . . . . . . . 131
Selective catching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

9 Regular Expressions 138


Creating a regular expression . . . . . . . . . . . . . . . . . . . . . . . 138
Testing for matches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Sets of characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
International characters . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Repeating parts of a pattern . . . . . . . . . . . . . . . . . . . . . . . . 142
Grouping subexpressions . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Matches and groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
The Date class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Boundaries and look-ahead . . . . . . . . . . . . . . . . . . . . . . . . . 145
Choice patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
The mechanics of matching . . . . . . . . . . . . . . . . . . . . . . . . 147
Backtracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
The replace method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Greed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Dynamically creating RegExp objects . . . . . . . . . . . . . . . . . . 152
The search method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
The lastIndex property . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Parsing an INI file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Code units and characters . . . . . . . . . . . . . . . . . . . . . . . . . 157
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

v
10 Modules 161
Modular programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
ES modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
CommonJS modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Building and bundling . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Module design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

11 Asynchronous Programming 173


Asynchronicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Promises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Failure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Carla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Breaking In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Async functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
A Corvid Art Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
The event loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Asynchronous bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

12 Project: A Programming Language 193


Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
The evaluator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Special forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
The environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Cheating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

13 JavaScript and the Browser 206


Networks and the Internet . . . . . . . . . . . . . . . . . . . . . . . . . 206
The Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
HTML and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

vi
In the sandbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Compatibility and the browser wars . . . . . . . . . . . . . . . . . . . 212

14 The Document Object Model 214


Document structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
The standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Moving through the tree . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Finding elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Changing the document . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Creating nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Styling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Cascading styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Query selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Positioning and animating . . . . . . . . . . . . . . . . . . . . . . . . . 228
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

15 Handling Events 233


Event handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Events and DOM nodes . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Event objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Default actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Key events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Pointer events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Scroll events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Focus events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Load event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Events and the event loop . . . . . . . . . . . . . . . . . . . . . . . . . 245
Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Debouncing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

16 Project: A Platform Game 251


The game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
The technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252

vii
Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Reading a level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Actors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Motion and collision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Actor updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Tracking keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Running the game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

17 Drawing on Canvas 273


SVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
The canvas element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Lines and surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Drawing a pie chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Storing and clearing transformations . . . . . . . . . . . . . . . . . . . 286
Back to the game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Choosing a graphics interface . . . . . . . . . . . . . . . . . . . . . . . 292
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

18 HTTP and Forms 296


The protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Browsers and HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Fetch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
HTTP sandboxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Appreciating HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Security and HTTPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Form fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Disabled fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
The form as a whole . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Text fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Checkboxes and radio buttons . . . . . . . . . . . . . . . . . . . . . . . 308
Select fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

viii
File fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Storing data client-side . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315

19 Project: A Pixel Art Editor 317


Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
The state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
DOM building . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
The canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
The application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Drawing tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Saving and loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Undo history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Let’s draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Why is this so hard? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335

20 Node.js 337
Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
The node command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Installing with NPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
The file system module . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
The HTTP module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
A file server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352

21 Project: Skill-Sharing Website 354


Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Long polling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
HTTP interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
The server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
The client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371

Exercise Hints 373


Program Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373

ix
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Data Structures: Objects and Arrays . . . . . . . . . . . . . . . . . . . 375
Higher-Order Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
The Secret Life of Objects . . . . . . . . . . . . . . . . . . . . . . . . . 378
Project: A Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Bugs and Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Asynchronous Programming . . . . . . . . . . . . . . . . . . . . . . . . 382
Project: A Programming Language . . . . . . . . . . . . . . . . . . . . 384
The Document Object Model . . . . . . . . . . . . . . . . . . . . . . . 385
Handling Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Project: A Platform Game . . . . . . . . . . . . . . . . . . . . . . . . . 387
Drawing on Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
HTTP and Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Project: A Pixel Art Editor . . . . . . . . . . . . . . . . . . . . . . . . 391
Node.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Project: Skill-Sharing Website . . . . . . . . . . . . . . . . . . . . . . . 394

x
“We think we are creating the system for our own purposes. We
believe we are making it in our own image... But the computer is
not really like us. It is a projection of a very slim part of ourselves:
that portion devoted to logic, order, rule, and clarity.”
—Ellen Ullman, Close to the Machine: Technophilia and its
Discontents

Introduction
This is a book about instructing computers. Computers are about as common
as screwdrivers today, but they are quite a bit more complex, and making them
do what you want them to do isn’t always easy.
If the task you have for your computer is a common, well-understood one,
such as showing you your email or acting like a calculator, you can open the
appropriate application and get to work. But for unique or open-ended tasks,
there often is no appropriate application.
That is where programming may come in. Programming is the act of con-
structing a program—a set of precise instructions telling a computer what to do.
Because computers are dumb, pedantic beasts, programming is fundamentally
tedious and frustrating.
Fortunately, if you can get over that fact—and maybe even enjoy the rigor
of thinking in terms that dumb machines can deal with—programming can be
rewarding. It allows you to do things in seconds that would take forever by
hand. It is a way to make your computer tool do things that it couldn’t do
before. On top of that, it makes for a wonderful game of puzzle solving and
abstract thinking.
Most programming is done with programming languages. A programming
language is an artificially constructed language used to instruct computers. It
is interesting that the most effective way we’ve found to communicate with a
computer borrows so heavily from the way we communicate with each other.
Like human languages, computer languages allow words and phrases to be
combined in new ways, making it possible to express ever new concepts.
At one point, language-based interfaces, such as the BASIC and DOS prompts
of the 1980s and 1990s, were the main method of interacting with computers.
For routine computer use, these have largely been replaced with visual inter-
faces, which are easier to learn but offer less freedom. But if you know where
to look, the languages are still there. One of them, JavaScript, is built into
every modern web browser—and is thus available on almost every device.
This book will try to make you familiar enough with this language to do
useful and amusing things with it.

1
On programming
Besides explaining JavaScript, I will introduce the basic principles of program-
ming. Programming, it turns out, is hard. The fundamental rules are simple
and clear, but programs built on top of these rules tend to become complex
enough to introduce their own rules and complexity. You’re building your own
maze, in a way, and you can easily get lost in it.
There will be times when reading this book feels terribly frustrating. If you
are new to programming, there will be a lot of new material to digest. Much of
this material will then be combined in ways that require you to make additional
connections.
It is up to you to make the necessary effort. When you are struggling to
follow the book, do not jump to any conclusions about your own capabilities.
You are fine—you just need to keep at it. Take a break, reread some material,
and make sure you read and understand the example programs and exercises.
Learning is hard work, but everything you learn is yours and will make further
learning easier.

When action grows unprofitable, gather information; when infor-


mation grows unprofitable, sleep.
—Ursula K. Le Guin, The Left Hand of Darkness

A program is many things. It is a piece of text typed by a programmer, it is


the directing force that makes the computer do what it does, it is data in the
computer’s memory, and at the same time it controls the actions performed
on this memory. Analogies that try to compare programs to familiar objects
tend to fall short. A superficially fitting one is to compare a program to a
machine—lots of separate parts tend to be involved, and to make the whole
thing tick, we have to consider the ways in which these parts interconnect and
contribute to the operation of the whole.
A computer is a physical machine that acts as a host for these immaterial
machines. Computers themselves can do only stupidly straightforward things.
The reason they are so useful is that they do these things at an incredibly
high speed. A program can ingeniously combine an enormous number of these
simple actions to do very complicated things.
A program is a building of thought. It is costless to build, it is weightless,
and it grows easily under our typing hands. But as a program grows, so does
its complexity. The skill of programming is the skill of building programs
that don’t confuse yourself. The best programs are those that manage to do
something interesting while still being easy to understand.

2
Some programmers believe that this complexity is best managed by using
only a small set of well-understood techniques in their programs. They have
composed strict rules (“best practices”) prescribing the form programs should
have and carefully stay within their safe little zone.
This is not only boring, it is ineffective. New problems often require new
solutions. The field of programming is young and still developing rapidly, and
it is varied enough to have room for wildly different approaches. There are
many terrible mistakes to make in program design, and you should go ahead
and make them at least once so that you understand them. A sense of what a
good program looks like is developed with practice, not learned from a list of
rules.

Why language matters


In the beginning, at the birth of computing, there were no programming lan-
guages. Programs looked something like this:
00110001 00000000 00000000
00110001 00000001 00000001
00110011 00000001 00000010
01010001 00001011 00000010
00100010 00000010 00001000
01000011 00000001 00000000
01000001 00000001 00000001
00010000 00000010 00000000
01100010 00000000 00000000

This is a program to add the numbers from 1 to 10 together and print the
result: 1 + 2 + ... + 10 = 55. It could run on a simple hypothetical machine.
To program early computers, it was necessary to set large arrays of switches
in the right position or punch holes in strips of cardboard and feed them to
the computer. You can imagine how tedious and error-prone this procedure
was. Even writing simple programs required much cleverness and discipline.
Complex ones were nearly inconceivable.
Of course, manually entering these arcane patterns of bits (the ones and
zeros) did give the programmer a profound sense of being a mighty wizard.
And that has to be worth something in terms of job satisfaction.
Each line of the previous program contains a single instruction. It could be
written in English like this:

1. Store the number 0 in memory location 0.

3
Random documents with unrelated
content Scribd suggests to you:
XV. FEJEZET.

Egy nap Abbáziában.


Az utolsó Frideczky öregségének egyik legboldogabb napját
töltötte Senkhy János szerkesztő urral az ivándi birtokon.
Csak hétfőn reggel mentek vissza a városba. A báró a lakásáig
fuvarozta Jánost, akit megölelt, mielőtt az autóból kilépett volna:
– Gyere fel a klubba, öcsém, sokszor gyere fel, hadd legyen egy
kis örömem az életemből!
János tiz forintot adott a soffőrnek. A báró látta ezt a kocsiból és
megelégedetten morogta magának:
– Uri ember, nagyszerü uri ember! Mikor János három nap mulva
ujra felnézett a klubba, Füredy gróf ezzel fogadta:
– Na barátom, maga megbolonditotta az öreget. Csak magáról
beszél. Egy negyedórahosszat előadást tartott a miniszterelnöknek a
maga kiválóságairól. Menjen, menjen, már várja!
János ez alkalommal is megtette Frideczkynek azt a szivességet,
hogy vesztett nála egy parti sakkot és nyert is tőle egyet.
Idejét egyébiránt a legszebb semmittevéssel töltötte, egyetlen
komoly tennivalója az volt, hogy mindennap levelet kellett irnia
Adélnak, aki ehhez a mindennapi levélhez abszolut ragaszkodott.
János, aki papiroson nagyon gyatrán tudta csak kifejezni gondolatait,
érzelmeit pedig majdnem sehogysem, arra szoritkozott, hogy
életének napieseményeit irta meg Brioniba. Viszont Adél meleg és
kedves leveleket irt, szerelmeseket, mint egy szerető, érdeklődőket,
mint egy feleség, gondoskodókat, mint egy anya. Adél levelei mindig
derüsek és jókedvüek voltak, betegségről, gyógyulásról az asszony
sohasem irt egyetlen igét sem.
Julius közepén Adél letáviratozta Jánost Abbáziába. János ment.
Nagyon meglepte, hogy az asszony már Fiuméban, a
pályaudvaron várt rá. Valósággal ugy ugrott a nyakába, hogy
megcsókolja:
– De Adél! – szólt szemrehányóan a fiu – mért jött ide?
– Jánoska, ne beszélj! Te ezt nem érted. Nem tudtam parancsolni
magamnak, hogy ne jőjjek, mert nem tudtam volna megállni, hogy
mikor meglátlak az abbáziai molón, meg ne csókoljalak. Ott nem
tehettem volna, mert ott mindenki ismer. Itt megtehettem, látod,
meg is tettem.
A hajóig az asszony apróra kikérdezte Jánost, ugy mintha nem is
leveleztek volna, mintha semmitsem tudna életéről.
– De ne arról beszéljünk – mondta János a hajón, mikor már
lélegzethez jutott. – Hanem magáról. Hogy van?
– Nagyszerüen, Jánoska! Nézz meg!
A hajó orrán álltak, merő napfényben. János megnézte az
asszonyt. Az arca-bőre sötét volt és fényes, a szeme szinte villogott
ebből a sötétségből. Most is nagyon szép volt, csak a vonásai
rajzolódtak határozottabban s a szemének volt erősebb tüze.
– Igazán jól? – kérdezte János.
– De mennyire igazán!
– Hát akkor mért marad még tovább is Brioniban?
– Az kell… hogy egészen meggyógyuljak.
– Mért nem jön fel Abbáziába és mért nem jöhetek ide én is?
– Mert… mert azt még nem szabad Jánoska… Hogy igazán,
egészen meggyógyuljak.
És az asszony szeme fátylas lett. De vigyázott magára, a köny
csak ellepte a szemét, annyira megszaporodni nem engedte, hogy
lebuggyanjon, szeme héján tulra.
Az egész nap tengerparti kószálással telt el. Az asszony ragyogott
és beszélt s csak óvatosan hintette el azokat a mondanivalóit,
amikért Jánost Abbáziába hivta.
– Jánoska – mondta ebéd után, mikor a szines ernyő alatt itták a
feketét a terraszon. – A mandátum meglesz, de nehogy elhanyagolja
az öreg Frideczkyt. A gróftól is tudom, nemcsak a maga leveleiből,
hogy milyen nagy jó barátságban vannak.
– Ugyan! – nevetett János – az csak tréfa.
– Ne, ne, ne higyje, hogy tréfa. Majd meglátja, milyen jó az öreg
Frideczkyvel jóban lenni.
– De hiszen félretolt ember, Adélka, senkise törődik az öreggel.
– Az mindegy. Maga csak maradjon a barátja, majd én
visszakerülök Pestre, akkor én is bemutattatom magamat az
öregnek.
– Maga? Minek?
– Csak. Már régóta hallom, hogy milyen érdekes ember. Még
meghal, mielőtt megismerhetném. Vagy ő, vagy én.
– Mit mond?
– Csak tréfáltam, Senkike. Ne féljen. Ő hal meg, nem én!
Délután négykor az asszony hirtelen egyebet penditett meg:
– Hatkor indul a hajóm, megyek vissza és még akartam mondani
valamit.
– Csak nem megy el?
– De elmegyek.
– Igy?
– Hogyan igy, Jánoska?
– Még nem voltunk egy percig magunk közt.
– Nem is leszünk, Jánoska. Nincs szerelem. Most láttam magát,
az nekem elég. Ebből megélek a nyár végéig. Több nincs, többnek
nem szabad lenni.
– Adél!…
– Azt akartam mondani, hogy maga azért ne tegye tönkre a
nyarát. Azt én nem engedem.
– Hát mit csináljak? Ha maga elkerget maga mellől!
– Tudja mit… menjen a Balaton mellé, az közelebb van hozzám
is. Ha hivom, hamarabb jöhet.
– A Balaton? Hova mehet egy magános ember a Balatonon,
hiszen tudja, hogy ott sehol egy tisztességes hotel. De ha
parancsolja…
– Nem, nem parancsolom, Jánoska. Ne menjen csak ugy… legyen
a vendége valakinek.
(Adél ugy tett, mintha keresgélne, hogy kihez is küldhetné
Jánost.)
– Senki se hivott.
– Nem? Csodálom. Pedig Gotthelfék mondták nekem, milyen
szivesen lehivnák magukhoz nyárra.
– Nem hivtak.
– Hát akkor majd hivják.
– Nem hiszem.
– Hát ha majd hivják, menjen le hozzájuk.
– Unalmas emberek.
– Nem is olyan unalmasak, Jánoska. A lányok nagyon kedvesek.
– Alig ismerem őket.
– Arra lesz elég ideje nyáron. Igérje meg, hogy elmegy, ha
hivják.
János megigérte; meg volt győződve róla, hogy Gotthelfék ugyse
hivják.
Ahogy a hajó indulásának az ideje közeledett, Adél mind
csendesebb lett, az arcát elhagyta a fény, csak a szeme tüzelt még
jobban. A szeme-sarka néha idegesen összerándult.
– Jánoska, Jánoska, szivem! – szakadt ki a száján minden ok és
összefüggés nélkül. Aztán nagyon birkózott magával, legyőzte és
rendbehozta magát s elindultak a móló felé. A sürü-melegü
alkonyatban a levegő tele volt jószagokkal, renyheséggel,
kivánkozással.
– Szép, – mondta János, ahogy a kis parkból a tenger mellé
kiértek és végignéztek a Kvarneró szemsimogató kékjén.
– Brioni még szebb – mondta az asszony. – Még szebb! Ó de
nehéz, de nehéz…! – tette hozzá és nem fejezte be a mondatát.
Tikkadt bucsu következett, csók nélkül. Adél zsebkendőt
lobogtatott a hajóról. János a kalapját lóbálta. Mikor a hajó Lovrána
felé annyira megkisebbedett, hogy a lobogó zsebkendőt már ugy
sem lehetett volna látni, csak egy matróz látta, hogy az a nagyon
szép szőke hölgy lement a hölgyszalonba, ahol még senki sem volt
ilyenkor, hosszában elnyult a piros bársony ülésen és ugy sirt, olyan
rázkódó nagy sirással sirt, hogy a szőke haj lebomlott a fejéről.
(Vége az I. kötetnek)
*** END OF THE PROJECT GUTENBERG EBOOK DOKTOR SENKI (1.
KÖTET) ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like