Skip to content

Commit f30e0d4

Browse files
committed
minor
1 parent 5e9eca3 commit f30e0d4

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

1-js/01-getting-started/2-manuals-specifications/article.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33

44
This book is a *tutorial*. It aims to help you gradually learn the language. But once you're familiar with the basics, you'll need other sources.
55

6-
76
## Specification
87

98
**The ECMA-262 specification** contains the most in-depth, detailed and formalized information about JavaScript. It defines the language.
109

11-
But being that formalized, it's difficult to understand at first. So if you need the most trustworthy source of information about the language details, it's the right place. But it's not for everyday use.
10+
But being that formalized, it's difficult to understand at first. So if you need the most trustworthy source of information about the language details, the specification is the right place. But it's not for everyday use.
1211

1312
The latest draft is at <https://tc39.es/ecma262/>.
1413

15-
To read about bleeding-edge features, that are not yet widely supported, see proposals at <https://github.com/tc39/proposals>.
14+
To read about new bleeding-edge features, that are "almost standard", see proposals at <https://github.com/tc39/proposals>.
1615

1716
Also, if you're in developing for the browser, then there are other specs covered in the [second part](info:browser-environment) of the tutorial.
1817

1-js/05-data-types/03-string/article.md

+32-22
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let double = "double-quoted";
1717
let backticks = `backticks`;
1818
```
1919

20-
Single and double quotes are essentially the same. Backticks, however, allow us to embed any expression into the string, including function calls:
20+
Single and double quotes are essentially the same. Backticks, however, allow us to embed any expression into the string, by wrapping it in `${…}`:
2121

2222
```js run
2323
function sum(a, b) {
@@ -39,7 +39,11 @@ let guestList = `Guests:
3939
alert(guestList); // a list of guests, multiple lines
4040
```
4141

42-
If we try to use single or double quotes in the same way, there will be an error:
42+
Looks natural, right? But single or double quotes do not work this way.
43+
44+
If we use them and try to use multiple lines, there'll be an error:
45+
46+
4347
```js run
4448
let guestList = "Guests: // Error: Unexpected token ILLEGAL
4549
* John";
@@ -60,27 +64,33 @@ let guestList = "Guests:\n * John\n * Pete\n * Mary";
6064
alert(guestList); // a multiline list of guests
6165
```
6266

63-
For example, these two lines describe the same:
67+
For example, these two lines are equal, just written differently:
6468

6569
```js run
66-
alert( "Hello\nWorld" ); // two lines using a "newline symbol"
70+
let str1 = "Hello\nWorld"; // two lines using a "newline symbol"
6771

6872
// two lines using a normal newline and backticks
69-
alert( `Hello
70-
World` );
73+
let str2 = `Hello
74+
World`;
75+
76+
alert(str1 == str2); // true
7177
```
7278

73-
There are other, less common "special" characters as well. Here's the list:
79+
There are other, less common "special" characters.
80+
81+
Here's the full list:
7482

7583
| Character | Description |
7684
|-----------|-------------|
77-
|`\b`|Backspace|
78-
|`\f`|Form feed|
7985
|`\n`|New line|
80-
|`\r`|Carriage return|
86+
|`\r`|Carriage return: not used alone. Windows text files use a combination of two characters `\n\r` to represent a line break. |
87+
|`\'`, `\"`|Quotes|
88+
|`\\`|Backslash|
8189
|`\t`|Tab|
82-
|`\uNNNN`|A unicode symbol with the hex code `NNNN`, for instance `\u00A9` -- is a unicode for the copyright symbol `©`. It must be exactly 4 hex digits. |
83-
|`\u{NNNNNNNN}`|Some rare characters are encoded with two unicode symbols, taking up to 4 bytes. This long unicode requires braces around it.|
90+
|`\b`, `\f`,`\v` | Backspace, Form Feed, Vertical Tab -- kept for compatibility, not used nowadays. |
91+
|`\xXX`|Unicode character with the given hexadimal unicode `XX`, e.g. `'\x7A'` is the same as `'z'`.|
92+
|`\uXXXX`|A unicode symbol with the hex code `XXXX` in UTF-16 encoding, for instance `\u00A9` -- is a unicode for the copyright symbol `©`. It must be exactly 4 hex digits. |
93+
|`\u{X…XXXXXX}` (1 to 6 hex characters)|A unicode symbol with the given UTF-32 encoding. Some rare characters are encoded with two unicode symbols, taking up to 4 bytes. This way we can insert long codes. |
8494

8595
Examples with unicode:
8696

@@ -102,7 +112,7 @@ alert( 'I*!*\'*/!*m the Walrus!' ); // *!*I'm*/!* the Walrus!
102112

103113
As you can see, we have to prepend the inner quote by the backslash `\'`, because otherwise it would indicate the string end.
104114

105-
Of course, that refers only to the quotes that are the same as the enclosing ones. So, as a more elegant solution, we could switch to double quotes or backticks instead:
115+
Of course, only to the quotes that are the same as the enclosing ones need to be escaped. So, as a more elegant solution, we could switch to double quotes or backticks instead:
106116

107117
```js run
108118
alert( `I'm the Walrus!` ); // I'm the Walrus!
@@ -455,7 +465,7 @@ Let's recap these methods to avoid any confusion:
455465
```smart header="Which one to choose?"
456466
All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core JavaScript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere.
457467
458-
The author finds themself using `slice` almost all the time.
468+
Of the other two variants, `slice` is a little bit more flexible, it allows negative arguments and shorter to write. So, it's enough to remember solely `slice` of these three methods.
459469
```
460470

461471
## Comparing strings
@@ -530,7 +540,7 @@ The characters are compared by their numeric code. The greater code means that t
530540

531541
### Correct comparisons
532542

533-
The "right" algorithm to do string comparisons is more complex than it may seem, because alphabets are different for different languages. The same-looking letter may be located differently in different alphabets.
543+
The "right" algorithm to do string comparisons is more complex than it may seem, because alphabets are different for different languages.
534544

535545
So, the browser needs to know the language to compare.
536546

@@ -550,7 +560,7 @@ For instance:
550560
alert( 'Österreich'.localeCompare('Zealand') ); // -1
551561
```
552562

553-
This method actually has two additional arguments specified in [the documentation](mdn:js/String/localeCompare), which allows it to specify the language (by default taken from the environment) and setup additional rules like case sensitivity or should `"a"` and `"á"` be treated as the same etc.
563+
This method actually has two additional arguments specified in [the documentation](mdn:js/String/localeCompare), which allows it to specify the language (by default taken from the environment, letter order depends on the language) and setup additional rules like case sensitivity or should `"a"` and `"á"` be treated as the same etc.
554564

555565
## Internals, Unicode
556566

@@ -580,7 +590,7 @@ We actually have a single symbol in each of the strings above, but the `length`
580590

581591
`String.fromCodePoint` and `str.codePointAt` are few rare methods that deal with surrogate pairs right. They recently appeared in the language. Before them, there were only [String.fromCharCode](mdn:js/String/fromCharCode) and [str.charCodeAt](mdn:js/String/charCodeAt). These methods are actually the same as `fromCodePoint/codePointAt`, but don't work with surrogate pairs.
582592

583-
But, for instance, getting a symbol can be tricky, because surrogate pairs are treated as two characters:
593+
Getting a symbol can be tricky, because surrogate pairs are treated as two characters:
584594

585595
```js run
586596
alert( '𝒳'[0] ); // strange symbols...
@@ -608,7 +618,7 @@ In many languages there are symbols that are composed of the base character with
608618

609619
For instance, the letter `a` can be the base character for: `àáâäãåā`. Most common "composite" character have their own code in the UTF-16 table. But not all of them, because there are too many possible combinations.
610620

611-
To support arbitrary compositions, UTF-16 allows us to use several unicode characters. The base character and one or many "mark" characters that "decorate" it.
621+
To support arbitrary compositions, UTF-16 allows us to use several unicode characters: the base character followed by one or many "mark" characters that "decorate" it.
612622

613623
For instance, if we have `S` followed by the special "dot above" character (code `\u0307`), it is shown as Ṡ.
614624

@@ -634,7 +644,7 @@ For instance:
634644
alert( 'S\u0307\u0323' ); // Ṩ, S + dot above + dot below
635645
alert( 'S\u0323\u0307' ); // Ṩ, S + dot below + dot above
636646

637-
alert( 'S\u0307\u0323' == 'S\u0323\u0307' ); // false
647+
alert( 'S\u0307\u0323' == 'S\u0323\u0307' ); // false, different characters (?!)
638648
```
639649

640650
To solve this, there exists a "unicode normalization" algorithm that brings each string to the single "normal" form.
@@ -660,7 +670,7 @@ If you want to learn more about normalization rules and variants -- they are des
660670

661671
## Summary
662672

663-
- There are 3 types of quotes. Backticks allow a string to span multiple lines and embed expressions.
673+
- There are 3 types of quotes. Backticks allow a string to span multiple lines and embed expressions `${…}`.
664674
- Strings in JavaScript are encoded using UTF-16.
665675
- We can use special characters like `\n` and insert letters by their unicode using `\u...`.
666676
- To get a character, use: `[]`.
@@ -673,6 +683,6 @@ There are several other helpful methods in strings:
673683

674684
- `str.trim()` -- removes ("trims") spaces from the beginning and end of the string.
675685
- `str.repeat(n)` -- repeats the string `n` times.
676-
- ...and more. See the [manual](mdn:js/String) for details.
686+
- ...and more to be found in the [manual](mdn:js/String).
677687

678-
Strings also have methods for doing search/replace with regular expressions. But that topic deserves a separate chapter, so we'll return to that later.
688+
Strings also have methods for doing search/replace with regular expressions. But that's big topic, so it's explained in a separate tutorial section <info:regular-expressions>.

5-network/09-resume-upload/upload-resume.view/server.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ function onUpload(req, res) {
3232

3333
let fileStream;
3434

35-
// for byte 0, create a new file, otherwise check the size and append to existing one
36-
if (startByte == 0) {
35+
// if startByte is 0 or not set, create a new file, otherwise check the size and append to existing one
36+
if (!startByte) {
3737
upload.bytesReceived = 0;
3838
fileStream = fs.createWriteStream(filePath, {
3939
flags: 'w'
4040
});
4141
debug("New file created: " + filePath);
4242
} else {
43+
// we can check on-disk file size as well to be sure
4344
if (upload.bytesReceived != startByte) {
4445
res.writeHead(400, "Wrong start byte");
4546
res.end(upload.bytesReceived);

5-network/09-resume-upload/upload-resume.view/uploader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Uploader {
55
this.onProgress = onProgress;
66

77
// create fileId that uniquely identifies the file
8-
// we can also add user session identifier, to make it even more unique
8+
// we could also add user session identifier (if had one), to make it even more unique
99
this.fileId = file.name + '-' + file.size + '-' + +file.lastModifiedDate;
1010
}
1111

0 commit comments

Comments
 (0)