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: 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.
Copy file name to clipboardExpand all lines: 9-regular-expressions/01-regexp-introduction/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
@@ -29,7 +29,7 @@ In both cases `regexp` becomes an instance of the built-in `RegExp` class.
29
29
30
30
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.
31
31
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:
33
33
34
34
```js
35
35
let tag =prompt("What tag do you want to find?", "h2");
@@ -56,7 +56,7 @@ There are only 6 of them in JavaScript:
56
56
: Enables "dotall" mode, that allows a dot `pattern:.` to match newline character `\n` (covered in the chapter <info:regexp-character-classes>).
57
57
58
58
`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>.
60
60
61
61
`pattern:y`
62
62
: "Sticky" mode: searching at the exact position in the text (covered in the chapter <info:regexp-sticky>)
0 commit comments