33# Introduction
44
55This is a book about instructing ((computer))s. Computers are about as
6- common as screwdrivers today. But they are quite a bit more complex
7- than screwdrivers, and making them do the precise thing you want them
8- to do isn't always easy.
6+ common as screwdrivers today, but they are quite a bit more complex,
7+ and making them do the things you want them to do isn't always easy.
98
109If the task you have for your computer is a common, well-understood
1110one, such as showing you your email or acting like a calculator, you
@@ -22,7 +21,7 @@ programming is fundamentally tedious and frustrating.
2221Fortunately, if you can get over that, and maybe even enjoy the rigor
2322of thinking in terms that dumb machines can deal with, programming can
2423be very rewarding. It allows you to do things that would take
25- _ forever_ by hand in seconds. It is a way to make your computer tool
24+ _ forever_ by hand, in seconds. It is a way to make your computer tool
2625do things that it couldn't do before. And it provides a wonderful
2726exercise in abstract thinking.
2827
@@ -38,9 +37,10 @@ express ever new concepts.
3837
3938Language-based interfaces, which at one point were the main way in
4039which people interacted with computers, have largely been replaced
41- with easier, more limited interfaces. But they are still there, if you
42- know where to look. One such language, JavaScript, is built into every
43- modern web ((browser)) and is thus available on almost every device.
40+ with easier, more constrained interfaces. But they are still there, if
41+ you know where to look. One such language, JavaScript, is built into
42+ every modern web ((browser)) and is thus available on almost every
43+ device.
4444
4545{{indexsee "web browser", browser}}
4646
@@ -53,10 +53,10 @@ do useful and amusing things with it.
5353
5454Besides explaining JavaScript, I will also introduce the basic
5555principles of programming. Programming, it turns out, is hard. The
56- fundamental rules are typically simple and clear. But programs built
57- on top of these rules tend to become complex enough to introduce their
58- own rules and complexity. You're building your own maze, in a way, and
59- you might just get lost in it.
56+ fundamental rules are simple and clear, but programs built on top of
57+ these rules tend to become complex enough to introduce their own rules
58+ and complexity. You're building your own maze, in a way, and you might
59+ just get lost in it.
6060
6161{{index learning}}
6262
@@ -68,9 +68,9 @@ require you to make additional connections.
6868It is up to you to make the necessary effort. When you are struggling
6969to follow the book, do not jump to any conclusions about your own
7070capabilities. You are fine—you just need to keep at it. Take a break,
71- reread some material, and _ always _ make sure you read and understand
72- the example programs and ((exercises)). Learning is hard work, but
73- everything you learn is yours and will make subsequent learning
71+ reread some material, and make sure you read and understand the
72+ example programs and ((exercises)). Learning is hard work, but
73+ everything you learn is yours, and will make subsequent learning
7474easier.
7575
7676{{quote {author: "Ursula K. Le Guin", title: "The Left Hand of Darkness"}
@@ -94,12 +94,12 @@ involved, and to make the whole thing tick, we have to consider the
9494ways in which these parts interconnect and contribute to the operation
9595of the whole.
9696
97- A ((computer)) is a machine built to act as a host for these
98- immaterial machines. Computers themselves can do only stupidly
99- straightforward things. The reason they are so useful is that they do
100- these things at an incredibly high ((speed)). A program can
101- ingeniously combine an enormous number of these simple actions in
102- order to do very complicated things.
97+ A ((computer)) is a machine that acts as a host for these immaterial
98+ machines. Computers themselves can do only stupidly straightforward
99+ things. The reason they are so useful is that they do these things at
100+ an incredibly high ((speed)). A program can ingeniously combine an
101+ enormous number of these simple actions in order to do very
102+ complicated things.
103103
104104{{index [ programming, "joy of"] }}
105105
@@ -127,9 +127,9 @@ This is not only boring, it is also ineffective. New problems often
127127require new solutions. The field of programming is young and still
128128developing rapidly, and is varied enough to have space for wildly
129129different approaches. There are many terrible mistakes to make in
130- program design, so go ahead and make them so that you understand them
131- better . A sense of what a good program looks like is developed in
132- practice, not learned from a list of rules.
130+ program design, and you should go ahead and make them so that you
131+ understand them . A sense of what a good program looks like is
132+ developed in practice, not learned from a list of rules.
133133
134134## Why language matters
135135
@@ -173,18 +173,16 @@ satisfaction.
173173Each line of the previous program contains a single instruction. It
174174could be written in English like this:
175175
176- ``` {lang: "text/plain"}
177- 1. Store the number 0 in memory location 0.
178- 2. Store the number 1 in memory location 1.
179- 3. Store the value of memory location 1 in memory location 2.
180- 4. Subtract the number 11 from the value in memory location 2.
181- 5. If the value in memory location 2 is the number 0,
182- continue with instruction 9.
183- 6. Add the value of memory location 1 to memory location 0.
184- 7. Add the number 1 to the value of memory location 1.
185- 8. Continue with instruction 3.
186- 9. Output the value of memory location 0.
187- ```
176+ 1 . Store the number 0 in memory location 0.
177+ 2 . Store the number 1 in memory location 1.
178+ 3 . Store the value of memory location 1 in memory location 2.
179+ 4 . Subtract the number 11 from the value in memory location 2.
180+ 5 . If the value in memory location 2 is the number 0,
181+ continue with instruction 9.
182+ 6 . Add the value of memory location 1 to memory location 0.
183+ 7 . Add the number 1 to the value of memory location 1.
184+ 8 . Continue with instruction 3.
185+ 9 . Output the value of memory location 0.
188186
189187{{index readability, naming, variable}}
190188
@@ -234,17 +232,17 @@ console.log(total);
234232// → 55
235233```
236234
237- {{index "while loop", loop}}
235+ {{index "while loop", loop, "curly braces" }}
238236
239237This version gives us a few more improvements. Most importantly, there
240238is no need to specify the way we want the program to jump back and
241- forth anymore. The ` while ` language construct takes care of that. It
242- continues executing the block (wrapped in braces) below it as long as
243- the condition it was given holds. That condition is ` count <= 10 ` ,
244- which means “_ count_ is less than or equal to 10”. We no longer have
245- to create a temporary value and compare that to zero, which was an
239+ forth anymore. The ` while ` construct takes care of that. It continues
240+ executing the block (wrapped in braces) below it as long as the
241+ condition it was given holds. That condition is ` count <= 10 ` , which
242+ means “_ count_ is less than or equal to 10”. We no longer have to
243+ create a temporary value and compare that to zero, which was just an
246244uninteresting detail. Part of the power of programming languages is
247- that they take care of uninteresting details for us.
245+ that they can take care of uninteresting details for us.
248246
249247{{index "console.log"}}
250248
@@ -276,10 +274,10 @@ and `range`.)
276274
277275A good programming language helps the programmer by allowing them to
278276talk about the actions that the computer has to perform on a higher
279- level. It helps omit uninteresting details, provides convenient
280- building blocks (such as ` while ` and ` console.log ` ), allows you to
281- define your own building blocks (such as ` sum ` and ` range ` ), and makes
282- those blocks easy to compose.
277+ level. It helps omit details, provides convenient building blocks
278+ (such as ` while ` and ` console.log ` ), allows you to define your own
279+ building blocks (such as ` sum ` and ` range ` ), and makes those blocks
280+ easy to compose.
283281
284282## What is JavaScript?
285283
@@ -319,17 +317,17 @@ language.
319317
320318{{index [ JavaScript, "weaknesses of"] , debugging}}
321319
322- There are those who will say _ terrible_ things about the JavaScript
323- language. Many of these things are true. When I was required to write
324- something in JavaScript for the first time, I quickly came to despise
325- it. It would accept almost anything I typed but interpret it in a way
326- that was completely different from what I meant. This had a lot to do
327- with the fact that I did not have a clue what I was doing, of course,
328- but there is a real issue here: JavaScript is ridiculously liberal in
329- what it allows. The idea behind this design was that it would make
330- programming in JavaScript easier for beginners. In actuality, it
331- mostly makes finding problems in your programs harder because the
332- system will not point them out to you.
320+ There are those who will say _ terrible_ things about JavaScript. Many
321+ of these things are true. When I was required to write something in
322+ JavaScript for the first time, I quickly came to despise it. It would
323+ accept almost anything I typed but interpret it in a way that was
324+ completely different from what I meant. This had a lot to do with the
325+ fact that I did not have a clue what I was doing, of course, but there
326+ is a real issue here: JavaScript is ridiculously liberal in what it
327+ allows. The idea behind this design was that it would make programming
328+ in JavaScript easier for beginners. In actuality, it mostly makes
329+ finding problems in your programs harder because the system will not
330+ point them out to you.
333331
334332{{index [ JavaScript, "flexibility of"] , flexibility}}
335333
@@ -349,9 +347,10 @@ underway on an ambitious version 4, which planned a number of radical
349347improvements and extensions to the language. Changing a living, widely
350348used language in such a radical way turned out to be politically
351349difficult, and work on the version 4 was abandoned in 2008, leading to
352- the much less ambitious version 5 coming out in 2009. Then, in 2015, a
353- major update, including some of the ideas planned for version 4, was
354- made. Since then we've had new, small updates every year.
350+ a much less ambitious version 5, which only made some uncontroversial
351+ improvements, coming out in 2009. Then in 2015 version 6 came out, a
352+ major update which included some of the ideas planned for version 4.
353+ Since then we've had new, small updates every year.
355354
356355The fact that the language is evolving means that browsers have to
357356constantly keep up, and if you're using an older one, it may not
@@ -375,9 +374,9 @@ outside of the browser.
375374
376375Code is the text that makes up programs. Most chapters in this book
377376contain quite a lot of it. I believe reading code and writing ((code))
378- are indispensable parts of ((learning)) to program, so try to not just
379- glance over the examples. Read them attentively and understand them.
380- This may be slow and confusing at first, but I promise that you will
377+ are indispensable parts of ((learning)) to program. Try to not just
378+ glance over the examples—read them attentively and understand them.
379+ This may be slow and confusing at first, but I promise that you'll
381380quickly get the hang of it. The same goes for the ((exercises)). Don't
382381assume you understand them until you've actually written a working
383382solution.
402401
403402The easiest way to run the example code in the book, and to experiment
404403with it, is to look it up in the online version of the book at
405- [ _ eloquentjavascript.net_ ] ( https://eloquentjavascript.net/ ) . There, you
406- can click any code example to edit and run it and to see the output it
407- produces. To work on the exercises, go to
404+ [ _ eloquentjavascript.net_ ] ( https://eloquentjavascript.net/ ) . There,
405+ you can click any code example to edit and run it and to see the
406+ output it produces. To work on the exercises, go to
408407[ _ eloquentjavascript.net/code_ ] ( https://eloquentjavascript.net/code ) ,
409408which provides starting code for each coding exercise and allows you
410409to look at the solutions.
414413{{index "developer tools", "JavaScript console"}}
415414
416415If you want to run the programs defined in this book outside of the
417- book's sandbox , some care is required. Many examples stand on their
416+ book's website , some care is required. Many examples stand on their
418417own and should work in any JavaScript environment. But code in later
419418chapters is often written for a specific environment (the browser or
420419Node.js) and can run only there. In addition, many chapters define
@@ -433,27 +432,28 @@ two chapters are devoted to ((Node.js)), another environment to
433432program JavaScript in.
434433
435434Throughout the book, there are five _ project chapters_ , which describe
436- larger example programs to give you a taste of real programming. In
437- order of appearance, we will work through building a [ robot] ( robot ) , a
438- [ programming language] ( language ) , a [ platform game] ( game ) , a [ paint
439- program] ( paint ) , and a [ dynamic website] ( skillsharing ) .
435+ larger example programs to give you a taste of actual programming. In
436+ order of appearance, we will work through building a [ delivery
437+ robot] ( robot ) , a [ programming language] ( language ) , a [ platform
438+ game] ( game ) , a [ pixel paint program] ( paint ) , and a [ dynamic
439+ website] ( skillsharing ) .
440440
441441The language part of the book starts with four chapters to introduce
442442the basic structure of the JavaScript language. They introduce
443443[ control structures] ( program_structure ) (such as the ` while ` word you
444444saw in this introduction), [ functions] ( functions ) (writing your own
445445building blocks), and [ data structures] ( data ) . After these, you will
446- be able to write simple programs. Next, Chapters [ ?] ( higher_order ) and
446+ be able to write basic programs. Next, Chapters [ ?] ( higher_order ) and
447447[ ?] ( object ) introduce techniques to use functions and objects to write
448- more _ abstract_ code and thus keep complexity under control.
448+ more _ abstract_ code and keep complexity under control.
449449
450- After a [ first project chapter] ( robot ) , the first part of the book
451- continues with chapters on [ error handling and fixing] ( error ) , on
450+ After a [ first project chapter] ( robot ) , the language part of the book
451+ continues with chapters on [ error handling and bug fixing] ( error ) ,
452452[ regular expressions] ( regexp ) (an important tool for working with
453- text), on [ modularity] ( modules ) (another defense against complexity),
454- and on [ asynchronous programming] ( async ) (dealing with events that
455- take time). The [ second project chapter] ( language ) concludes the first
456- part of the book.
453+ text), [ modularity] ( modules ) (another defense against complexity), and
454+ [ asynchronous programming] ( async ) (dealing with events that take
455+ time). The [ second project chapter] ( language ) concludes the first part
456+ of the book.
457457
458458The second part, Chapters [ ?] ( browser ) to [ ?] ( paint ) , describes the
459459tools that browser JavaScript has access to. You'll learn to display
@@ -463,7 +463,7 @@ user input ([Chapter ?](event)), and communicate over the network
463463part.
464464
465465After that, [ Chapter ?] ( node ) describes Node.js, and [ Chapter
466- ?] ( skillsharing ) builds a small web system using that tool.
466+ ?] ( skillsharing ) builds a small website using that tool.
467467
468468{{if commercial
469469
0 commit comments