Skip to content

Commit abf1c1e

Browse files
authored
Merge pull request #200 from javascript-tutorial/sync-23e85b3c
Sync with upstream @ 23e85b3
2 parents 6d245f5 + 11edd53 commit abf1c1e

File tree

28 files changed

+94
-72
lines changed

28 files changed

+94
-72
lines changed

1-js/02-first-steps/08-operators/article.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ alert(2 + 2 + '1' ); // "41" and not "221"
106106
107107
Here, operators work one after another. The first `+` sums two numbers, so it returns `4`, then the next `+` adds the string `1` to it, so it's like `4 + '1' = 41`.
108108

109+
```js run
110+
alert('1' + 2 + 2); // "122" and not "14"
111+
```
112+
Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`.
113+
109114
The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers.
110115
111116
Here's the demo for subtraction and division:

1-js/03-code-quality/06-polyfills/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Two interesting libraries of polyfills are:
7878
7979
## Summary
8080
81-
In this chapter we'd like to motivate you to study modern and even "bleeding-edge" langauge features, even if they aren't yet well-supported by JavaScript engines.
81+
In this chapter we'd like to motivate you to study modern and even "bleeding-edge" language features, even if they aren't yet well-supported by JavaScript engines.
8282
8383
Just don't forget to use transpiler (if using modern syntax or operators) and polyfills (to add functions that may be missing). And they'll ensure that the code works.
8484

1-js/05-data-types/03-string/3-truncate/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The maximal length must be `maxlength`, so we need to cut it a little shorter, to give space for the ellipsis.
22

3-
Note that there is actually a single unicode character for an ellipsis. That's not three dots.
3+
Note that there is actually a single Unicode character for an ellipsis. That's not three dots.
44

55
```js run demo
66
function truncate(str, maxlength) {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let guestList = "Guests: // Error: Unexpected token ILLEGAL
5050

5151
Single and double quotes come from ancient times of language creation when the need for multiline strings was not taken into account. Backticks appeared much later and thus are more versatile.
5252

53-
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. This is called "tagged templates". This feature makes it easier to implement custom templating, but is rarely used in practice. You can read more about it in the [manual](mdn:/JavaScript/Reference/Template_literals#Tagged_templates).
53+
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. This is called "tagged templates". This feature makes it easier to implement custom templating, but is rarely used in practice. You can read more about it in the [manual](mdn:/JavaScript/Reference/Template_literals#Tagged_templates).
5454

5555
## Special characters
5656

@@ -86,16 +86,16 @@ Here's the full list:
8686
|`\\`|Backslash|
8787
|`\t`|Tab|
8888
|`\b`, `\f`, `\v`| Backspace, Form Feed, Vertical Tab -- kept for compatibility, not used nowadays. |
89-
|`\xXX`|Unicode character with the given hexadecimal unicode `XX`, e.g. `'\x7A'` is the same as `'z'`.|
90-
|`\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. |
91-
|`\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 4 bytes. This way we can insert long codes. |
89+
|`\xXX`|Unicode character with the given hexadecimal Unicode `XX`, e.g. `'\x7A'` is the same as `'z'`.|
90+
|`\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. |
91+
|`\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 4 bytes. This way we can insert long codes. |
9292

93-
Examples with unicode:
93+
Examples with Unicode:
9494

9595
```js run
9696
alert( "\u00A9" ); // ©
97-
alert( "\u{20331}" ); // 佫, a rare Chinese hieroglyph (long unicode)
98-
alert( "\u{1F60D}" ); // 😍, a smiling face symbol (another long unicode)
97+
alert( "\u{20331}" ); // 佫, a rare Chinese hieroglyph (long Unicode)
98+
alert( "\u{1F60D}" ); // 😍, a smiling face symbol (another long Unicode)
9999
```
100100

101101
All special characters start with a backslash character `\`. It is also called an "escape character".
@@ -499,7 +499,7 @@ All strings are encoded using [UTF-16](https://en.wikipedia.org/wiki/UTF-16). Th
499499
alert( String.fromCodePoint(90) ); // Z
500500
```
501501
502-
We can also add unicode characters by their codes using `\u` followed by the hex code:
502+
We can also add Unicode characters by their codes using `\u` followed by the hex code:
503503
504504
```js run
505505
// 90 is 5a in hexadecimal system
@@ -608,7 +608,7 @@ In many languages there are symbols that are composed of the base character with
608608

609609
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.
610610

611-
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.
611+
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.
612612

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

@@ -626,7 +626,7 @@ For example:
626626
alert( 'S\u0307\u0323' ); // Ṩ
627627
```
628628

629-
This provides great flexibility, but also an interesting problem: two characters may visually look the same, but be represented with different unicode compositions.
629+
This provides great flexibility, but also an interesting problem: two characters may visually look the same, but be represented with different Unicode compositions.
630630

631631
For instance:
632632

@@ -639,7 +639,7 @@ alert( `s1: ${s1}, s2: ${s2}` );
639639
alert( s1 == s2 ); // false though the characters look identical (?!)
640640
```
641641

642-
To solve this, there exists a "unicode normalization" algorithm that brings each string to the single "normal" form.
642+
To solve this, there exists a "Unicode normalization" algorithm that brings each string to the single "normal" form.
643643

644644
It is implemented by [str.normalize()](mdn:js/String/normalize).
645645

@@ -663,7 +663,7 @@ If you want to learn more about normalization rules and variants -- they are des
663663

664664
- There are 3 types of quotes. Backticks allow a string to span multiple lines and embed expressions `${…}`.
665665
- Strings in JavaScript are encoded using UTF-16.
666-
- We can use special characters like `\n` and insert letters by their unicode using `\u...`.
666+
- We can use special characters like `\n` and insert letters by their Unicode using `\u...`.
667667
- To get a character, use: `[]`.
668668
- To get a substring, use: `slice` or `substring`.
669669
- To lowercase/uppercase a string, use: `toLowerCase/toUpperCase`.

1-js/99-js-misc/01-proxy/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ For every internal method, there's a trap in this table: the name of the method
6767
| `[[PreventExtensions]]` | `preventExtensions` | [Object.preventExtensions](mdn:/JavaScript/Reference/Global_Objects/Object/preventExtensions) |
6868
| `[[DefineOwnProperty]]` | `defineProperty` | [Object.defineProperty](mdn:/JavaScript/Reference/Global_Objects/Object/defineProperty), [Object.defineProperties](mdn:/JavaScript/Reference/Global_Objects/Object/defineProperties) |
6969
| `[[GetOwnProperty]]` | `getOwnPropertyDescriptor` | [Object.getOwnPropertyDescriptor](mdn:/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor), `for..in`, `Object.keys/values/entries` |
70-
| `[[OwnPropertyKeys]]` | `ownKeys` | [Object.getOwnPropertyNames](mdn:/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames), [Object.getOwnPropertySymbols](mdn:/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols), `for..in`, `Object/keys/values/entries` |
70+
| `[[OwnPropertyKeys]]` | `ownKeys` | [Object.getOwnPropertyNames](mdn:/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames), [Object.getOwnPropertySymbols](mdn:/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols), `for..in`, `Object.keys/values/entries` |
7171

7272
```warn header="Invariants"
7373
JavaScript enforces some invariants -- conditions that must be fulfilled by internal methods and traps.

2-ui/2-events/05-dispatch-events/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ We can generate not only completely new events, that we invent for our own purpo
88

99
## Event constructor
1010

11-
Build-in event classes form a hierarchy, similar to DOM element classes. The root is the built-in [Event](http://www.w3.org/TR/dom/#event) class.
11+
Built-in event classes form a hierarchy, similar to DOM element classes. The root is the built-in [Event](http://www.w3.org/TR/dom/#event) class.
1212

1313
We can create `Event` objects like this:
1414

2-ui/99-ui-misc/02-selection-range/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ With these methods we can do basically anything with selected nodes.
211211

212212
Here's the test stand to see them in action:
213213

214-
```html run autorun height=260
214+
```html run refresh autorun height=260
215215
Click buttons to run methods on the selection, "resetExample" to reset it.
216216

217217
<p id="p">Example: <i>italic</i> and <b>bold</b></p>

4-binary/02-text-decoder/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
What if the binary data is actually a string? For instance, we received a file with textual data.
44

5-
The build-in [TextDecoder](https://encoding.spec.whatwg.org/#interface-textdecoder) object allows to read the value into an an actual JavaScript string, given the buffer and the encoding.
5+
The build-in [TextDecoder](https://encoding.spec.whatwg.org/#interface-textdecoder) object allows to read the value into an actual JavaScript string, given the buffer and the encoding.
66

77
We first need to create it:
88
```js
@@ -12,7 +12,7 @@ let decoder = new TextDecoder([label], [options]);
1212
- **`label`** -- the encoding, `utf-8` by default, but `big5`, `windows-1251` and many other are also supported.
1313
- **`options`** -- optional object:
1414
- **`fatal`** -- boolean, if `true` then throw an exception for invalid (non-decodable) characters, otherwise (default) replace them with character `\uFFFD`.
15-
- **`ignoreBOM`** -- boolean, if `true` then ignore BOM (an optional byte-order unicode mark), rarely needed.
15+
- **`ignoreBOM`** -- boolean, if `true` then ignore BOM (an optional byte-order Unicode mark), rarely needed.
1616

1717
...And then decode:
1818

5-network/02-formdata/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ As you can see, that's almost one-liner:
4747
</script>
4848
```
4949

50-
In this example, the server code is not presented, as it's beyound our scope. The server accepts the POST request and replies "User saved".
50+
In this example, the server code is not presented, as it's beyond our scope. The server accepts the POST request and replies "User saved".
5151

5252
## FormData Methods
5353

9-regular-expressions/01-regexp-introduction/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ In both cases `regexp` becomes an instance of the built-in `RegExp` class.
2929

3030
The main difference between these two syntaxes is that pattern using slashes `/.../` does not allow for expressions to be inserted (like string template literals with `${...}`). They are fully static.
3131

32-
Slashes are used when we know the regular expression at the code writing time -- and that's the most common situation. While `new RegExp`, is more often used when we need to create a regexp "on the fly" from a dynamically generated string. For instance:
32+
Slashes are used when we know the regular expression at the code writing time -- and that's the most common situation. While `new RegExp` is more often used when we need to create a regexp "on the fly" from a dynamically generated string. For instance:
3333

3434
```js
3535
let tag = prompt("What tag do you want to find?", "h2");
@@ -56,7 +56,7 @@ There are only 6 of them in JavaScript:
5656
: Enables "dotall" mode, that allows a dot `pattern:.` to match newline character `\n` (covered in the chapter <info:regexp-character-classes>).
5757

5858
`pattern:u`
59-
: Enables full unicode support. The flag enables correct processing of surrogate pairs. More about that in the chapter <info:regexp-unicode>.
59+
: Enables full Unicode support. The flag enables correct processing of surrogate pairs. More about that in the chapter <info:regexp-unicode>.
6060

6161
`pattern:y`
6262
: "Sticky" mode: searching at the exact position in the text (covered in the chapter <info:regexp-sticky>)

0 commit comments

Comments
 (0)