You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/08-operators/article.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,6 +106,11 @@ alert(2 + 2 + '1' ); // "41" and not "221"
106
106
107
107
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`.
108
108
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
+
109
114
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.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,7 @@ Two interesting libraries of polyfills are:
78
78
79
79
## Summary
80
80
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.
82
82
83
83
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.
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.
52
52
53
-
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func`string`</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`string`</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).
54
54
55
55
## Special characters
56
56
@@ -86,16 +86,16 @@ Here's the full list:
86
86
|`\\`|Backslash|
87
87
|`\t`|Tab|
88
88
|`\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'`.|
|`\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'`.|
|`\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. |
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)
99
99
```
100
100
101
101
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
499
499
alert( String.fromCodePoint(90) ); // Z
500
500
```
501
501
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:
503
503
504
504
```js run
505
505
// 90 is 5a in hexadecimal system
@@ -608,7 +608,7 @@ In many languages there are symbols that are composed of the base character with
608
608
609
609
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.
610
610
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.
612
612
613
613
For instance, if we have `S` followed by the special "dot above" character (code `\u0307`), it is shown as Ṡ.
614
614
@@ -626,7 +626,7 @@ For example:
626
626
alert( 'S\u0307\u0323' ); // Ṩ
627
627
```
628
628
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.
Copy file name to clipboardExpand all lines: 1-js/11-async/05-promise-api/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -309,15 +309,15 @@ In practice, this method is almost never used.
309
309
310
310
## Summary
311
311
312
-
There are 5 static methods of `Promise` class:
312
+
There are 6 static methods of `Promise` class:
313
313
314
314
1. `Promise.all(promises)` -- waits for all promises to resolve and returns an array of their results. If any of the given promises rejects, it becomes the error of `Promise.all`, and all other results are ignored.
315
315
2. `Promise.allSettled(promises)` (recently added method) -- waits for all promises to settle and returns their results as an array of objects with:
316
316
- `status`: `"fulfilled"` or `"rejected"`
317
317
- `value` (if fulfilled) or `reason` (if rejected).
318
318
3. `Promise.race(promises)` -- waits for the first promise to settle, and its result/error becomes the outcome.
319
-
4. `Promise.any(promises)` -- waits for the first promise to fulfill, and its result becomes the outcome. If all of the given promises are rejected, [`AggregateError`](mdn:js/AggregateError) becomes the error of `Promise.any`.
319
+
4. `Promise.any(promises)` (recently added method) -- waits for the first promise to fulfill, and its result becomes the outcome. If all of the given promises are rejected, [`AggregateError`](mdn:js/AggregateError) becomes the error of `Promise.any`.
320
320
5. `Promise.resolve(value)` -- makes a resolved promise with the given value.
321
321
6. `Promise.reject(error)` -- makes a rejected promise with the given error.
322
322
323
-
Of these five, `Promise.all` is probably the most common in practice.
323
+
Of all these, `Promise.all` is probably the most common in practice.
Copy file name to clipboardExpand all lines: 4-binary/02-text-decoder/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
What if the binary data is actually a string? For instance, we received a file with textual data.
4
4
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.
6
6
7
7
We first need to create it:
8
8
```js
@@ -12,7 +12,7 @@ let decoder = new TextDecoder([label], [options]);
12
12
-**`label`** -- the encoding, `utf-8` by default, but `big5`, `windows-1251` and many other are also supported.
13
13
-**`options`** -- optional object:
14
14
-**`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.
0 commit comments