Skip to content

Commit 9da047e

Browse files
committed
Second page review
1 parent afcb089 commit 9da047e

12 files changed

+36
-38
lines changed

00_intro.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Some programmers believe that this complexity is best managed by using only a sm
6666

6767
{{index experiment}}
6868

69-
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.
69+
This is not only boringit 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.
7070

7171
## Why language matters
7272

@@ -110,7 +110,7 @@ Each line of the previous program contains a single instruction. It could be wri
110110

111111
{{index readability, naming, binding}}
112112

113-
Although that is already more readable than the soup of bits, it is still rather obscure. Using names instead of numbers for the instructions and memory locations helps:
113+
Although that is already more readable than the soup of bits, it is still rather obscure. Using names instead of numbers for the instructions and memory locations helps.
114114

115115
```{lang: "null"}
116116
Set “total” to 0.

01_values.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ The difference in meaning between `undefined` and `null` is an accident of JavaS
357357

358358
{{index NaN, "type coercion"}}
359359

360-
In the [Introduction](intro), I mentioned that JavaScript goes out of its way to accept almost any program you give it, even programs that do odd things. This is nicely demonstrated by the following expressions:
360+
In the [introduction](intro), I mentioned that JavaScript goes out of its way to accept almost any program you give it, even programs that do odd things. This is nicely demonstrated by the following expressions:
361361

362362
```
363363
console.log(8 * null)
@@ -422,7 +422,7 @@ We can use this functionality as a way to fall back on a default value. If you h
422422

423423
{{index "?? operator", null, undefined}}
424424

425-
The `??` operator resembles `||`, but returns the value on the right only if the one on the left is null or undefined, not if it is some other value that can be converted to `false`. Often, this is preferable to the behavior of `||`.
425+
The `??` operator resembles `||` but returns the value on the right only if the one on the left is `null` or `undefined`, not if it is some other value that can be converted to `false`. Often, this is preferable to the behavior of `||`.
426426

427427
```
428428
console.log(0 || 100);

02_program_structure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ Functions are special values that encapsulate a piece of program. You can invoke
629629

630630
{{index exercises}}
631631

632-
If you are unsure how to test your solutions to the exercises, refer to the [Introduction](intro).
632+
If you are unsure how to test your solutions to the exercises, refer to the [introduction](intro).
633633

634634
Each exercise starts with a problem description. Read this description and try to solve the exercise. If you run into problems, consider reading the hints [after the exercise]{if interactive}[at the [end of the book](hints)]{if book}. You can find full solutions to the exercises online at [_https://eloquentjavascript.net/code_](https://eloquentjavascript.net/code#2). If you want to learn something from the exercises, I recommend looking at the solutions only after you've solved the exercise, or at least after you've attacked it long and hard enough to have a slight headache.
635635

03_functions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ console.log("C", "O", 2);
351351

352352
{{index "call stack", "local binding", [function, "as value"], scope}}
353353

354-
The ability to treat functions as values, combined with the fact that local bindings are re-created every time a function is called, brings up an interesting question: what happens to local bindings when the function call that created them is no longer active?
354+
The ability to treat functions as values, combined with the fact that local bindings are re-created every time a function is called, brings up an interesting question: What happens to local bindings when the function call that created them is no longer active?
355355

356356
The following code shows an example of this. It defines a function, `wrapValue`, that creates a local binding. It then returns a function that accesses and returns this local binding.
357357

@@ -371,7 +371,7 @@ console.log(wrap2());
371371

372372
This is allowed and works as you'd hope—both instances of the binding can still be accessed. This situation is a good demonstration of the fact that local bindings are created anew for every call, and different calls don't affect each other's local bindings.
373373

374-
This feature—being able to reference a specific instance of a local binding in an enclosing scope—is called _((closure))_. A function that references bindings from local scopes around it is called _a_ closure. This behavior not only frees you from having to worry about the lifetimes of bindings, it also makes it possible to use function values in some creative ways.
374+
This feature—being able to reference a specific instance of a local binding in an enclosing scope—is called _((closure))_. A function that references bindings from local scopes around it is called _a_ closure. This behavior not only frees you from having to worry about the lifetimes of bindings but also makes it possible to use function values in some creative ways.
375375

376376
{{index "multiplier function"}}
377377

@@ -620,7 +620,7 @@ The first helper function in the ((farm example)), `printZeroPaddedWithLabel`, i
620620

621621
{{index substitution}}
622622

623-
A _pure_ function is a specific kind of value-producing function that not only has no side effects, but also doesn't rely on side effects from other code—for example, it doesn't read global bindings whose value might change. A pure function has the pleasant property that, when called with the same arguments, it always produces the same value (and doesn't do anything else). A call to such a function can be substituted by its return value without changing the meaning of the code. When you are not sure that a pure function is working correctly, you can test it by simply calling it and know that if it works in that context, it will work in any context. Nonpure functions tend to require more scaffolding to test.
623+
A _pure_ function is a specific kind of value-producing function that not only has no side effects but also doesn't rely on side effects from other code—for example, it doesn't read global bindings whose value might change. A pure function has the pleasant property that, when called with the same arguments, it always produces the same value (and doesn't do anything else). A call to such a function can be substituted by its return value without changing the meaning of the code. When you are not sure that a pure function is working correctly, you can test it by simply calling it and know that if it works in that context, it will work in any context. Nonpure functions tend to require more scaffolding to test.
624624

625625
{{index optimization, "console.log"}}
626626

04_data.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Back to the weresquirrel. A set of daily log entries can be represented as an ar
163163

164164
{{index [syntax, object], [property, definition], [braces, object], "{} (object)"}}
165165

166-
Values of the type _((object))_ are arbitrary collections of properties. One way to create an object is by using braces as an expression:
166+
Values of the type _((object))_ are arbitrary collections of properties. One way to create an object is by using braces as an expression.
167167

168168
```
169169
let day1 = {

05_higher_order.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Though I can fluently read only Latin characters, I appreciate the fact that peo
216216

217217
{{index "SCRIPTS dataset"}}
218218

219-
The example ((dataset)) contains some pieces of information about the 140 scripts defined in Unicode. It is available in the [coding sandbox](https://eloquentjavascript.net/code#5) for this chapter[ ([_https://eloquentjavascript.net/code#5_](https://eloquentjavascript.net/code#5))]{if book} as the `SCRIPTS` binding. The binding contains an array of objects, each of which describes a script:
219+
The example ((dataset)) contains some pieces of information about the 140 scripts defined in Unicode. It is available in the [coding sandbox](https://eloquentjavascript.net/code#5) for this chapter[ ([_https://eloquentjavascript.net/code#5_](https://eloquentjavascript.net/code#5))]{if book} as the `SCRIPTS` binding. The binding contains an array of objects, each of which describes a script.
220220

221221

222222
```{lang: "json"}
@@ -361,7 +361,7 @@ The Han script has more than 89,000 characters assigned to it in the Unicode sta
361361

362362
{{index loop, maximum}}
363363

364-
Consider how we would have written the previous example (finding the biggest script) without higher-order functions. The code is not that much worse:
364+
Consider how we would have written the previous example (finding the biggest script) without higher-order functions. The code is not that much worse.
365365

366366
```{test: no}
367367
let biggest = null;
@@ -381,7 +381,7 @@ There are a few more bindings, and the program is four lines longer, but it is s
381381

382382
{{id average_function}}
383383

384-
The abstractions these functions provide really shine when you need to _compose_ operations. As an example, let's write code that finds the average year of origin for living and dead scripts in the dataset:
384+
The abstractions these functions provide really shine when you need to _compose_ operations. As an example, let's write code that finds the average year of origin for living and dead scripts in the dataset.
385385

386386
```
387387
function average(array) {
@@ -398,7 +398,7 @@ console.log(Math.round(average(
398398

399399
As you can see, the dead scripts in Unicode are, on average, older than the living ones. This is not a terribly meaningful or surprising statistic. But I hope you'll agree that the code used to compute it isn't hard to read. You can see it as a pipeline: we start with all scripts, filter out the living (or dead) ones, take the years from those, average them, and round the result.
400400

401-
You could definitely also write this computation as one big ((loop)):
401+
You could definitely also write this computation as one big ((loop)).
402402

403403
```
404404
let total = 0, count = 0;
@@ -479,7 +479,7 @@ JavaScript's `charCodeAt` method gives you a code unit, not a full character cod
479479

480480
{{index "for/of loop", character}}
481481

482-
In the [previous chapter](data#for_of_loop), I mentioned that a `for`/`of` loop can also be used on strings. Like `codePointAt`, this type of loop was introduced at a time when people were acutely aware of the problems with UTF-16. When you use it to loop over a string, it gives you real characters, not code units:
482+
In the [previous chapter](data#for_of_loop), I mentioned that a `for`/`of` loop can also be used on strings. Like `codePointAt`, this type of loop was introduced at a time when people were acutely aware of the problems with UTF-16. When you use it to loop over a string, it gives you real characters, not code units.
483483

484484
```
485485
let roseDragon = "🌹🐉";
@@ -525,7 +525,7 @@ It uses another array method, `find`, which goes over the elements in the array
525525

526526
{{index "textScripts function", "Chinese characters"}}
527527

528-
Using `countBy`, we can write the function that tells us which scripts are used in a piece of text:
528+
Using `countBy`, we can write the function that tells us which scripts are used in a piece of text.
529529

530530
```{includeCode: strip_log, startCode: true}
531531
function textScripts(text) {

06_object.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ quote}}
1212

1313
{{figure {url: "img/chapter_picture_6.jpg", alt: "Illustration of a rabbit next to its prototype, a schematic representation of a rabbit", chapter: framed}}}
1414

15-
[Chapter ?](data) introduced JavaScript's objects as containers that hold other data.
16-
17-
In programming culture, _((object-oriented programming))_ is a set of techniques that use objects as the central principle of program organization. Though no one really agrees on its precise definition, object-oriented programming has shaped the design of many programming languages, including JavaScript. This chapter describes the way these ideas can be applied in JavaScript.
15+
[Chapter ?](data) introduced JavaScript's objects as containers that hold other data. In programming culture, _((object-oriented programming))_ is a set of techniques that use objects as the central principle of program organization. Though no one really agrees on its precise definition, object-oriented programming has shaped the design of many programming languages, including JavaScript. This chapter describes the way these ideas can be applied in JavaScript.
1816

1917
## Abstract Data Types
2018

08_error.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ In this book, we will continue using raw, dangerous, untyped JavaScript code.
129129

130130
If the language is not going to do much to help us find mistakes, we'll have to find them the hard way: by running the program and seeing whether it does the right thing.
131131

132-
Doing this by hand, again and again, is a really bad idea. Not only is it annoying, it also tends to be ineffective, since it takes too much time to exhaustively test everything every time you make a change.
132+
Doing this by hand, again and again, is a really bad idea. Not only is it annoying but it also tends to be ineffective, since it takes too much time to exhaustively test everything every time you make a change.
133133

134134
Computers are good at repetitive tasks, and testing is the ideal repetitive task. Automated testing is the process of writing a program that tests another program. Writing tests is a bit more work than testing manually, but once you've done it, you gain a kind of superpower: it takes you only a few seconds to verify that your program still behaves properly in all the situations you wrote tests for. When you break something, you'll immediately notice rather than randomly running into it at some later time.
135135

@@ -442,7 +442,7 @@ for (;;) {
442442

443443
{{index "infinite loop", "for loop", "catch keyword", debugging}}
444444

445-
The `for (;;)` construct is a way to intentionally create a loop that doesn't terminate on its own. We break out of the loop only when a valid direction is given. Unfortunately, we misspelled `promptDirection`, which will result in an "undefined variable" error. Because the `catch` block completely ignores its exception value (`e`), assuming it knows what the problem is, it wrongly treats the binding error as indicating bad input. Not only does this cause an infinite loop, it "buries" the useful error message about the misspelled binding.
445+
The `for (;;)` construct is a way to intentionally create a loop that doesn't terminate on its own. We break out of the loop only when a valid direction is given. Unfortunately, we misspelled `promptDirection`, which will result in an "undefined variable" error. Because the `catch` block completely ignores its exception value (`e`), assuming it knows what the problem is, it wrongly treats the binding error as indicating bad input. Not only does this cause an infinite loop but it also "buries" the useful error message about the misspelled binding.
446446

447447
As a general rule, don't blanket-catch exceptions unless it is for the purpose of "routing" them somewhere—for example, over the network to tell another system that our program crashed. And even then, think carefully about how you might be hiding information.
448448

10_modules.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Modules
44

5-
{{quote {author: "Tef", title: "Programming is Terrible", chapter: true}
5+
{{quote {author: "Tef", title: "programming is terrible", chapter: true}
66

77
Write code that is easy to delete, not easy to extend.
88

13_browser.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Such a connection acts as a two-way ((pipe)) through which bits can flow—the m
6464

6565
## The Web
6666

67-
The _((World Wide Web))_ (not to be confused with the ((internet)) as a whole) is a set of ((protocol))s and formats that allow us to visit web pages in a browser. "Web" refers to the fact that such pages can easily link to each other, thus connecting into a huge ((mesh)) that users can move through.
67+
The _((World Wide Web))_ (not to be confused with the ((internet)) as a whole) is a set of ((protocol))s and formats that allow us to visit web pages in a browser. The word _Web_ refers to the fact that such pages can easily link to each other, thus connecting into a huge ((mesh)) that users can move through.
6868

6969
To become part of the web, all you need to do is connect a machine to the ((internet)) and have it listen on port 80 with the ((HTTP)) protocol so that other computers can ask it for documents.
7070

@@ -96,7 +96,7 @@ If you type this URL into your browser's ((address bar)), the browser will try t
9696

9797
{{indexsee "HyperText Markup Language", HTML}}
9898

99-
_HTML_, which stands for _HyperText Markup Language_, is the document format used for web pages. An HTML document contains ((text)), as well as _((tag))s_ that give structure to the text, describing things such as links, paragraphs, and headings.
99+
_HTML_, which stands for HyperText Markup Language, is the document format used for web pages. An HTML document contains ((text)), as well as _((tag))s_ that give structure to the text, describing things such as links, paragraphs, and headings.
100100

101101
A short HTML document might look like this:
102102

14_dom.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ The `replaceChild` method is used to replace a child node with another one. It t
217217

218218
{{index "alt attribute", "img (HTML tag)", "createTextNode method"}}
219219

220-
Say we want to write a script that replaces all ((image))s (`<img>` tags) in the document with the text held in their `alt` attributes, which specifies an alternative textual representation of the image. This involves not only removing the images but adding a new text node to replace them.
220+
Say we want to write a script that replaces all ((image))s (`<img>` tags) in the document with the text held in their `alt` attributes, which specifies an alternative textual representation of the image. This involves not only removing the images but also adding a new text node to replace them.
221221

222222
```{lang: html}
223223
<p>The <img src="img/cat.png" alt="Cat"> in the
@@ -640,7 +640,7 @@ Moving in ((circle))s is done using the trigonometry functions `Math.cos` and `M
640640

641641
{{index coordinates, pi}}
642642

643-
`Math.cos` and `Math.sin` are useful for finding points that lie on a circle around point (0,0) with a radius of 1. Both functions interpret their argument as the position on this circle, with 0 denoting the point on the far right of the circle, going clockwise until 2π (about 6.28) has taken us around the whole circle. `Math.cos` tells you the x-coordinate of the point that corresponds to the given position, and `Math.sin` yields the y-coordinate. Positions (or angles) greater than 2π or less than 0 are valid—the rotation repeats so that _a_+2π refers to the same ((angle)) as _a_.
643+
`Math.cos` and `Math.sin` are useful for finding points that lie on a circle around point (0, 0) with a radius of 1. Both functions interpret their argument as the position on this circle, with 0 denoting the point on the far right of the circle, going clockwise until 2π (about 6.28) has taken us around the whole circle. `Math.cos` tells you the x-coordinate of the point that corresponds to the given position, and `Math.sin` yields the y-coordinate. Positions (or angles) greater than 2π or less than 0 are valid—the rotation repeats so that _a_+2π refers to the same ((angle)) as _a_.
644644

645645
{{index "PI constant"}}
646646

0 commit comments

Comments
 (0)