Skip to content

Commit 03c4ff6

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-4a8d8987
2 parents 5218028 + 4a8d898 commit 03c4ff6

File tree

122 files changed

+1068
-755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1068
-755
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ But being that formalized, it's difficult to understand at first. So if you need
1111

1212
The latest draft is at <https://tc39.es/ecma262/>.
1313

14-
To read about new bleeding-edge features, that are "almost standard", see proposals at <https://github.com/tc39/proposals>.
14+
To read about new bleeding-edge features, including those that are "almost standard" (so-called "stage 3"), see proposals at <https://github.com/tc39/proposals>.
1515

1616
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.
1717

@@ -28,7 +28,7 @@ Also, if you're in developing for the browser, then there are other specs covere
2828

2929
Also, we can use an internet search with phrases such as "RegExp MSDN" or "RegExp MSDN jscript".
3030

31-
## Feature support
31+
## Compatibility tables
3232

3333
JavaScript is a developing language, new features get added regularly.
3434

Diff for: 1-js/04-object-basics/01-object/article.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ We can add, remove and read files from it any time.
4949
Property values are accessible using the dot notation:
5050

5151
```js
52-
// get fields of the object:
52+
// get property values of the object:
5353
alert( user.name ); // John
5454
alert( user.age ); // 30
5555
```
@@ -105,7 +105,6 @@ That's because the dot requires the key to be a valid variable identifier. That
105105

106106
There's an alternative "square bracket notation" that works with any string:
107107

108-
109108
```js run
110109
let user = {};
111110

@@ -130,7 +129,7 @@ let key = "likes birds";
130129
user[key] = true;
131130
```
132131

133-
Here, the variable `key` may be calculated at run-time or depend on the user input. And then we use it to access the property. That gives us a great deal of flexibility. The dot notation cannot be used in a similar way.
132+
Here, the variable `key` may be calculated at run-time or depend on the user input. And then we use it to access the property. That gives us a great deal of flexibility.
134133

135134
For instance:
136135

@@ -146,6 +145,17 @@ let key = prompt("What do you want to know about the user?", "name");
146145
alert( user[key] ); // John (if enter "name")
147146
```
148147

148+
The dot notation cannot be used in a similar way:
149+
150+
```js run
151+
let user = {
152+
name: "John",
153+
age: 30
154+
};
155+
156+
let key = "name";
157+
user.key // undefined
158+
```
149159

150160
### Computed properties
151161

@@ -222,9 +232,10 @@ As we see from the code, the assignment to a primitive `5` is ignored.
222232
223233
That can become a source of bugs and even vulnerabilities if we intend to store arbitrary key-value pairs in an object, and allow a visitor to specify the keys.
224234
225-
In that case the visitor may choose "__proto__" as the key, and the assignment logic will be ruined (as shown above).
235+
In that case the visitor may choose `__proto__` as the key, and the assignment logic will be ruined (as shown above).
226236
227237
There is a way to make objects treat `__proto__` as a regular property, which we'll cover later, but first we need to know more about objects.
238+
228239
There's also another data structure [Map](info:map-set-weakmap-weakset), that we'll learn in the chapter <info:map-set-weakmap-weakset>, which supports arbitrary keys.
229240
````
230241

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ if (str.indexOf("Widget") != -1) {
314314

315315
One of the old tricks used here is the [bitwise NOT](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT) `~` operator. It converts the number to a 32-bit integer (removes the decimal part if exists) and then reverses all bits in its binary representation.
316316

317-
For 32-bit integers the call `~n` means exactly the same as `-(n+1)` (due to IEEE-754 format).
317+
In practice, that means a simple thing: for 32-bit integers `~n` equals `-(n+1)`.
318318

319319
For instance:
320320

@@ -345,7 +345,7 @@ It is usually not recommended to use language features in a non-obvious way, but
345345

346346
Just remember: `if (~str.indexOf(...))` reads as "if found".
347347

348-
Technically speaking, numbers are truncated to 32 bits by `~` operator, so there exist other big numbers that give `0`, the smallest is `~4294967295=0`. That makes such check is correct only if a string is not that long.
348+
To be precise though, as big numbers are truncated to 32 bits by `~` operator, there exist other numbers that give `0`, the smallest is `~4294967295=0`. That makes such check is correct only if a string is not that long.
349349

350350
Right now we can see this trick only in the old code, as modern JavaScript provides `.includes` method (see below).
351351

@@ -519,7 +519,7 @@ alert( str );
519519
// ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜ
520520
```
521521

522-
See? Capital characters go first, then a few special ones, then lowercase characters.
522+
See? Capital characters go first, then a few special ones, then lowercase characters, and `Ö` near the end of the output.
523523

524524
Now it becomes obvious why `a > Z`.
525525

@@ -631,10 +631,12 @@ This provides great flexibility, but also an interesting problem: two characters
631631
For instance:
632632

633633
```js run
634-
alert( 'S\u0307\u0323' ); // Ṩ, S + dot above + dot below
635-
alert( 'S\u0323\u0307' ); // Ṩ, S + dot below + dot above
634+
let s1 = 'S\u0307\u0323'; // Ṩ, S + dot above + dot below
635+
let s2 = 'S\u0323\u0307'; // Ṩ, S + dot below + dot above
636636

637-
alert( 'S\u0307\u0323' == 'S\u0323\u0307' ); // false, different characters (?!)
637+
alert( `s1: ${s1}, s2: ${s2}` );
638+
639+
alert( s1 == s2 ); // false though the characters look identical (?!)
638640
```
639641

640642
To solve this, there exists a "unicode normalization" algorithm that brings each string to the single "normal" form.

0 commit comments

Comments
 (0)