Skip to content

Commit 6cd5ff9

Browse files
committed
# Conflicts: # 1-js/01-getting-started/2-manuals-specifications/article.md # 1-js/05-data-types/07-map-set-weakmap-weakset/article.md # 1-js/05-data-types/10-date/3-weekday/solution.md # 1-js/07-object-oriented-programming/06-prototype-methods/article.md # 1-js/09-classes/01-class/article.md # 1-js/09-classes/05-extend-natives/article.md # 1-js/11-async/03-promise-chaining/article.md # 1-js/12-generators-iterators/1-generators/01-pseudo-random-generator/solution.md # 1-js/12-generators-iterators/1-generators/article.md # 1-js/13-modules/03-modules-dynamic-imports/article.md # 2-ui/1-document/11-coordinates/coords.png # 2-ui/1-document/11-coordinates/coords@2x.png # 2-ui/1-document/11-coordinates/document-window-coordinates-scroll.png # 2-ui/1-document/11-coordinates/document-window-coordinates-scroll@2x.png # 2-ui/1-document/11-coordinates/document-window-coordinates-zero.png # 2-ui/1-document/11-coordinates/document-window-coordinates-zero@2x.png # 2-ui/99-ui-misc/01-mutation-observer/article.md # 6-data-storage/01-cookie/article.md # 6-data-storage/02-localstorage/article.md # 8-web-components/2-custom-elements/article.md # 8-web-components/5-slots-composition/article.md # 8-web-components/6-shadow-dom-style/article.md # 8-web-components/7-shadow-dom-events/article.md # figures.sketch
2 parents b140203 + 8319c71 commit 6cd5ff9

100 files changed

Lines changed: 948 additions & 176 deletions

File tree

Some content is hidden

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

1-js/04-object-basics/01-object/article.md

Lines changed: 15 additions & 4 deletions
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

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

Lines changed: 8 additions & 6 deletions
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.

1-js/05-data-types/07-map-set-weakmap-weakset/01-array-unique-map/_js.view/solution.js renamed to 1-js/05-data-types/07-map-set/01-array-unique-map/_js.view/solution.js

File renamed without changes.

1-js/05-data-types/07-map-set-weakmap-weakset/01-array-unique-map/_js.view/test.js renamed to 1-js/05-data-types/07-map-set/01-array-unique-map/_js.view/test.js

File renamed without changes.

1-js/05-data-types/07-map-set-weakmap-weakset/01-array-unique-map/solution.md renamed to 1-js/05-data-types/07-map-set/01-array-unique-map/solution.md

File renamed without changes.

1-js/05-data-types/07-map-set-weakmap-weakset/01-array-unique-map/task.md renamed to 1-js/05-data-types/07-map-set/01-array-unique-map/task.md

File renamed without changes.

1-js/05-data-types/07-map-set-weakmap-weakset/02-filter-anagrams/_js.view/solution.js renamed to 1-js/05-data-types/07-map-set/02-filter-anagrams/_js.view/solution.js

File renamed without changes.

1-js/05-data-types/07-map-set-weakmap-weakset/02-filter-anagrams/_js.view/test.js renamed to 1-js/05-data-types/07-map-set/02-filter-anagrams/_js.view/test.js

File renamed without changes.

1-js/05-data-types/07-map-set-weakmap-weakset/02-filter-anagrams/solution.md renamed to 1-js/05-data-types/07-map-set/02-filter-anagrams/solution.md

File renamed without changes.

1-js/05-data-types/07-map-set-weakmap-weakset/02-filter-anagrams/task.md renamed to 1-js/05-data-types/07-map-set/02-filter-anagrams/task.md

File renamed without changes.

0 commit comments

Comments
 (0)