From f0ce7e97c6c3ff1d0c5b0e2c97f3d9358bcc310d Mon Sep 17 00:00:00 2001 From: joaquinelio Date: Mon, 3 Oct 2022 13:44:42 -0300 Subject: [PATCH 01/48] IE 9 --- 1-js/06-advanced-functions/08-settimeout-setinterval/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/06-advanced-functions/08-settimeout-setinterval/article.md b/1-js/06-advanced-functions/08-settimeout-setinterval/article.md index 5a40238b1..f96959988 100644 --- a/1-js/06-advanced-functions/08-settimeout-setinterval/article.md +++ b/1-js/06-advanced-functions/08-settimeout-setinterval/article.md @@ -27,7 +27,7 @@ Usually, that's a function. For historical reasons, a string of code can be pass : The delay before run, in milliseconds (1000 ms = 1 second), by default 0. `arg1`, `arg2`... -: Arguments for the function (not supported in IE9-) +: Arguments for the function For instance, this code calls `sayHi()` after one second: From 3a5d32ea8aa2eda70f3f57a840fbdc6d2e374363 Mon Sep 17 00:00:00 2001 From: aki-mizu Date: Wed, 5 Oct 2022 10:04:51 +0900 Subject: [PATCH 02/48] Remove typo Same as title --- 1-js/04-object-basics/09-object-toprimitive/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/09-object-toprimitive/article.md b/1-js/04-object-basics/09-object-toprimitive/article.md index 8b0008b11..0a16b5399 100644 --- a/1-js/04-object-basics/09-object-toprimitive/article.md +++ b/1-js/04-object-basics/09-object-toprimitive/article.md @@ -226,7 +226,7 @@ As we know already, many operators and functions perform type conversions, e.g. If we pass an object as an argument, then there are two stages of calculations: 1. The object is converted to a primitive (using the rules described above). -2. If the necessary for further calculations, the resulting primitive is also converted. +2. If necessary for further calculations, the resulting primitive is also converted. For instance: From 4573d0b1932feeacddc3f68444cfa352bc0e408b Mon Sep 17 00:00:00 2001 From: Teva Henry Date: Thu, 6 Oct 2022 00:46:36 +1300 Subject: [PATCH 03/48] Fix typos --- 6-data-storage/02-localstorage/article.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/6-data-storage/02-localstorage/article.md b/6-data-storage/02-localstorage/article.md index e4a4b3558..a99bcb653 100644 --- a/6-data-storage/02-localstorage/article.md +++ b/6-data-storage/02-localstorage/article.md @@ -10,7 +10,7 @@ We already have cookies. Why additional objects? - Also unlike cookies, the server can't manipulate storage objects via HTTP headers. Everything's done in JavaScript. - The storage is bound to the origin (domain/protocol/port triplet). That is, different protocols or subdomains infer different storage objects, they can't access data from each other. -Both storage objects provide same methods and properties: +Both storage objects provide the same methods and properties: - `setItem(key, value)` -- store key/value pair. - `getItem(key)` -- get the value by key. @@ -124,7 +124,7 @@ The latter works, because `Object.keys` only returns the keys that belong to the Please note that both key and value must be strings. -If were any other type, like a number, or an object, it gets converted to string automatically: +If they were any other type, like a number, or an object, they would get converted to a string automatically: ```js run localStorage.user = {name: "John"}; @@ -219,7 +219,7 @@ Modern browsers also support [Broadcast channel API](mdn:/api/Broadcast_Channel_ ## Summary -Web storage objects `localStorage` and `sessionStorage` allow to store key/value in the browser. +Web storage objects `localStorage` and `sessionStorage` allow to store key/value pairs in the browser. - Both `key` and `value` must be strings. - The limit is 5mb+, depends on the browser. From af4843bee2ab7675c3ecc641ab55566e36f26a20 Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 8 Oct 2022 21:43:57 +0600 Subject: [PATCH 04/48] =?UTF-8?q?=F0=9F=91=BE=20smth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/05-data-types/07-map-set/article.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/1-js/05-data-types/07-map-set/article.md b/1-js/05-data-types/07-map-set/article.md index 354070888..23c656202 100644 --- a/1-js/05-data-types/07-map-set/article.md +++ b/1-js/05-data-types/07-map-set/article.md @@ -14,7 +14,7 @@ But that's not enough for real life. That's why `Map` and `Set` also exist. Methods and properties are: -- `new Map()` -- creates the map. +- [`new Map()`](mdn:js/Map/Map) -- creates the map. - [`map.set(key, value)`](mdn:js/Map/set) -- stores the value by the key. - [`map.get(key)`](mdn:js/Map/get) -- returns the value by the key, `undefined` if `key` doesn't exist in map. - [`map.has(key)`](mdn:js/Map/has) -- returns `true` if the `key` exists, `false` otherwise. @@ -100,7 +100,6 @@ map.set('1', 'str1') ``` ```` - ## Iteration over Map For looping over a `map`, there are 3 methods: @@ -233,11 +232,11 @@ That's the same, because `Object.fromEntries` expects an iterable object as the ## Set -A `Set` is a special type collection - "set of values" (without keys), where each value may occur only once. +A [`Set`](mdn:js/Set) is a special type collection - "set of values" (without keys), where each value may occur only once. Its main methods are: -- `new Set(iterable)` -- creates the set, and if an `iterable` object is provided (usually an array), copies values from it into the set. +- [`new Set(iterable)`](mdn:js/Set/Set) -- creates the set, and if an `iterable` object is provided (usually an array), copies values from it into the set. - [`set.add(value)`](mdn:js/Set/add) -- adds a value, returns the set itself. - [`set.delete(value)`](mdn:js/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. - [`set.has(value)`](mdn:js/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. @@ -301,11 +300,11 @@ The same methods `Map` has for iterators are also supported: ## Summary -`Map` -- is a collection of keyed values. +[Map](mdn:js/Map) -- is a collection of keyed values. Methods and properties: -- `new Map([iterable])` -- creates the map, with optional `iterable` (e.g. array) of `[key,value]` pairs for initialization. +- [`new Map([iterable])`](mdn:js/Map/Map) -- creates the map, with optional `iterable` (e.g. array) of `[key,value]` pairs for initialization. - [`map.set(key, value)`](mdn:js/Map/set) -- stores the value by the key, returns the map itself. - [`map.get(key)`](mdn:js/Map/get) -- returns the value by the key, `undefined` if `key` doesn't exist in map. - [`map.has(key)`](mdn:js/Map/has) -- returns `true` if the `key` exists, `false` otherwise. @@ -318,11 +317,11 @@ The differences from a regular `Object`: - Any keys, objects can be keys. - Additional convenient methods, the `size` property. -`Set` -- is a collection of unique values. +[`Set`](mdn:js/Set) -- is a collection of unique values. Methods and properties: -- `new Set([iterable])` -- creates the set, with optional `iterable` (e.g. array) of values for initialization. +- [`new Set(iterable)`](mdn:js/Set/Set) -- creates the set, with optional `iterable` (e.g. array) of values for initialization. - [`set.add(value)`](mdn:js/Set/add) -- adds a value (does nothing if `value` exists), returns the set itself. - [`set.delete(value)`](mdn:js/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. - [`set.has(value)`](mdn:js/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. From 530dc9f3a59f5cf897b7a3d592ad996bfae76682 Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 8 Oct 2022 22:02:10 +0600 Subject: [PATCH 05/48] =?UTF-8?q?=F0=9F=91=BE=20smth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../08-weakmap-weakset/article.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/1-js/05-data-types/08-weakmap-weakset/article.md b/1-js/05-data-types/08-weakmap-weakset/article.md index 8d5a86981..bcf9e0fa3 100644 --- a/1-js/05-data-types/08-weakmap-weakset/article.md +++ b/1-js/05-data-types/08-weakmap-weakset/article.md @@ -54,13 +54,13 @@ john = null; // overwrite the reference */!* ``` -`WeakMap` is fundamentally different in this aspect. It doesn't prevent garbage-collection of key objects. +[`WeakMap`](mdn:js/WeakMap) is fundamentally different in this aspect. It doesn't prevent garbage-collection of key objects. Let's see what it means on examples. ## WeakMap -The first difference between `Map` and `WeakMap` is that keys must be objects, not primitive values: +The first difference between [`Map`](mdn:js/Map) and [`WeakMap`](mdn:js/WeakMap) is that keys must be objects, not primitive values: ```js run let weakMap = new WeakMap(); @@ -94,10 +94,10 @@ Compare it with the regular `Map` example above. Now if `john` only exists as th `WeakMap` has only the following methods: -- `weakMap.get(key)` -- `weakMap.set(key, value)` -- `weakMap.delete(key)` -- `weakMap.has(key)` +- [`weakMap.set(key, value)`](mdn:js/WeakMap/set) +- [`weakMap.get(key)`](mdn:js/WeakMap/get) +- [`weakMap.delete(key)`](mdn:js/WeakMap/delete) +- [`weakMap.has(key)`](mdn:js/WeakMap/has) Why such a limitation? That's for technical reasons. If an object has lost all other references (like `john` in the code above), then it is to be garbage-collected automatically. But technically it's not exactly specified *when the cleanup happens*. @@ -242,11 +242,11 @@ obj = null; ## WeakSet -`WeakSet` behaves similarly: +[`WeakSet`](mdn:js/WeakSet) behaves similarly: - It is analogous to `Set`, but we may only add objects to `WeakSet` (not primitives). - An object exists in the set while it is reachable from somewhere else. -- Like `Set`, it supports `add`, `has` and `delete`, but not `size`, `keys()` and no iterations. +- Like `Set`, it supports [`add`](mdn:js/Weakset/add), [`has`](mdn:js/Weakset/has) and [`delete`](mdn:js/Weakset/delete), but not `size`, `keys()` and no iterations. Being "weak", it also serves as additional storage. But not for arbitrary data, rather for "yes/no" facts. A membership in `WeakSet` may mean something about the object. @@ -280,9 +280,9 @@ The most notable limitation of `WeakMap` and `WeakSet` is the absence of iterati ## Summary -`WeakMap` is `Map`-like collection that allows only objects as keys and removes them together with associated value once they become inaccessible by other means. +[`WeakMap`](mdn:js/WeakMap) is `Map`-like collection that allows only objects as keys and removes them together with associated value once they become inaccessible by other means. -`WeakSet` is `Set`-like collection that stores only objects and removes them once they become inaccessible by other means. +[`WeakSet`](mdn:js/WeakSet) is `Set`-like collection that stores only objects and removes them once they become inaccessible by other means. Their main advantages are that they have weak reference to objects, so they can easily be removed by garbage collector. From 1d999c7abccc9168623e34e73819330fe68f00da Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 8 Oct 2022 22:10:29 +0600 Subject: [PATCH 06/48] =?UTF-8?q?=F0=9F=91=BE=20smth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/05-data-types/07-map-set/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/07-map-set/article.md b/1-js/05-data-types/07-map-set/article.md index 23c656202..ea8f59190 100644 --- a/1-js/05-data-types/07-map-set/article.md +++ b/1-js/05-data-types/07-map-set/article.md @@ -300,7 +300,7 @@ The same methods `Map` has for iterators are also supported: ## Summary -[Map](mdn:js/Map) -- is a collection of keyed values. +[`Map`](mdn:js/Map) -- is a collection of keyed values. Methods and properties: From 429caba04904b3698b2e4b0df90589f9fc176fb6 Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 8 Oct 2022 22:12:05 +0600 Subject: [PATCH 07/48] =?UTF-8?q?=F0=9F=91=BE=20smth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/05-data-types/07-map-set/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/05-data-types/07-map-set/article.md b/1-js/05-data-types/07-map-set/article.md index ea8f59190..15af9a265 100644 --- a/1-js/05-data-types/07-map-set/article.md +++ b/1-js/05-data-types/07-map-set/article.md @@ -236,7 +236,7 @@ A [`Set`](mdn:js/Set) is a special type collection - "set of values" (without ke Its main methods are: -- [`new Set(iterable)`](mdn:js/Set/Set) -- creates the set, and if an `iterable` object is provided (usually an array), copies values from it into the set. +- [`new Set([iterable])`](mdn:js/Set/Set) -- creates the set, and if an `iterable` object is provided (usually an array), copies values from it into the set. - [`set.add(value)`](mdn:js/Set/add) -- adds a value, returns the set itself. - [`set.delete(value)`](mdn:js/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. - [`set.has(value)`](mdn:js/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. @@ -321,7 +321,7 @@ The differences from a regular `Object`: Methods and properties: -- [`new Set(iterable)`](mdn:js/Set/Set) -- creates the set, with optional `iterable` (e.g. array) of values for initialization. +- [`new Set([iterable])`](mdn:js/Set/Set) -- creates the set, with optional `iterable` (e.g. array) of values for initialization. - [`set.add(value)`](mdn:js/Set/add) -- adds a value (does nothing if `value` exists), returns the set itself. - [`set.delete(value)`](mdn:js/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. - [`set.has(value)`](mdn:js/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. From 0c8e8833c903d5c46ea4a16e9a92e0023995f5c9 Mon Sep 17 00:00:00 2001 From: joaquinelio Date: Thu, 20 Oct 2022 16:30:17 -0300 Subject: [PATCH 08/48] typo *udefined --- 1-js/02-first-steps/12-nullish-coalescing-operator/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/12-nullish-coalescing-operator/article.md b/1-js/02-first-steps/12-nullish-coalescing-operator/article.md index 7dbf1835f..b2bc64f83 100644 --- a/1-js/02-first-steps/12-nullish-coalescing-operator/article.md +++ b/1-js/02-first-steps/12-nullish-coalescing-operator/article.md @@ -37,7 +37,7 @@ Here's the example with `user` assigned to a name: ```js run let user = "John"; -alert(user ?? "Anonymous"); // John (user is not null/udefined) +alert(user ?? "Anonymous"); // John (user is not null/undefined) ``` We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`. From 4edd6b5ca19e37a4b70289bd350f96b455679cd6 Mon Sep 17 00:00:00 2001 From: f6p Date: Thu, 20 Oct 2022 21:35:14 +0200 Subject: [PATCH 09/48] Proper Polish language inflection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello world! properly inflects as Witaj świecie! in Polish. Cheers 🍷 --- 9-regular-expressions/10-regexp-greedy-and-lazy/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/10-regexp-greedy-and-lazy/article.md b/9-regular-expressions/10-regexp-greedy-and-lazy/article.md index 2f656479d..e20175075 100644 --- a/9-regular-expressions/10-regexp-greedy-and-lazy/article.md +++ b/9-regular-expressions/10-regexp-greedy-and-lazy/article.md @@ -8,7 +8,7 @@ Let's take the following task as an example. We have a text and need to replace all quotes `"..."` with guillemet marks: `«...»`. They are preferred for typography in many countries. -For instance: `"Hello, world"` should become `«Hello, world»`. There exist other quotes, such as `„Witam, świat!”` (Polish) or `「你好,世界」` (Chinese), but for our task let's choose `«...»`. +For instance: `"Hello, world"` should become `«Hello, world»`. There exist other quotes, such as `„Witaj, świecie!”` (Polish) or `「你好,世界」` (Chinese), but for our task let's choose `«...»`. The first thing to do is to locate quoted strings, and then we can replace them. From 094aa104eb2affbc190ffe1a73c5cfed28810a6c Mon Sep 17 00:00:00 2001 From: joaquinelio Date: Thu, 20 Oct 2022 18:40:44 -0300 Subject: [PATCH 10/48] Add .at( ) to strings summary --- 1-js/05-data-types/03-string/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/05-data-types/03-string/article.md b/1-js/05-data-types/03-string/article.md index 618f8ef3b..60ce2b6f0 100644 --- a/1-js/05-data-types/03-string/article.md +++ b/1-js/05-data-types/03-string/article.md @@ -505,7 +505,7 @@ This method actually has two additional arguments specified in [the documentatio - There are 3 types of quotes. Backticks allow a string to span multiple lines and embed expressions `${…}`. - We can use special characters, such as a line break `\n`. -- To get a character, use: `[]`. +- To get a character, use: `[]` or `at` method. - To get a substring, use: `slice` or `substring`. - To lowercase/uppercase a string, use: `toLowerCase/toUpperCase`. - To look for a substring, use: `indexOf`, or `includes/startsWith/endsWith` for simple checks. @@ -519,4 +519,4 @@ There are several other helpful methods in strings: Strings also have methods for doing search/replace with regular expressions. But that's big topic, so it's explained in a separate tutorial section . -Also, as of now it's important to know that strings are based on Unicode encoding, and hence there're issues with comparisons. There's more about Unicode in the chapter . \ No newline at end of file +Also, as of now it's important to know that strings are based on Unicode encoding, and hence there're issues with comparisons. There's more about Unicode in the chapter . From 434e6371c3452b2fd51f911666c3c6b0c9037968 Mon Sep 17 00:00:00 2001 From: Vic <62945733+Victor-Nikliaiev@users.noreply.github.com> Date: Fri, 28 Oct 2022 03:16:00 -0500 Subject: [PATCH 11/48] For the completeness of example. because after all, ```let result1 = process(obj); // calculated``` would be ```undefined```. Also using this opportunity, wanted to say thanks to creator and editors of this great tutorial! --- 1-js/05-data-types/08-weakmap-weakset/article.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/1-js/05-data-types/08-weakmap-weakset/article.md b/1-js/05-data-types/08-weakmap-weakset/article.md index 8d5a86981..4101b4fd3 100644 --- a/1-js/05-data-types/08-weakmap-weakset/article.md +++ b/1-js/05-data-types/08-weakmap-weakset/article.md @@ -182,6 +182,7 @@ function process(obj) { let result = /* calculations of the result for */ obj; cache.set(obj, result); + return result; } return cache.get(obj); @@ -221,6 +222,7 @@ function process(obj) { let result = /* calculate the result for */ obj; cache.set(obj, result); + return result; } return cache.get(obj); From b3c7a7faac056e0f99c5522bfe4ee093793097e1 Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 29 Oct 2022 15:45:24 +0600 Subject: [PATCH 12/48] =?UTF-8?q?=F0=9F=91=BE=20add=20run=20button=20and?= =?UTF-8?q?=20remove=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/06-advanced-functions/04-var/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index 1579afb62..fcf28d936 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -56,9 +56,9 @@ alert(test); // ReferenceError: test is not defined */!* ``` -The same thing for loops: `var` cannot be block- or loop-local: +The same thing for loops: `var` cannot be block or loop-local: -```js +```js run for (var i = 0; i < 10; i++) { var one = 1; // ... From 515dc44884fd131e930cba0f1ae7e064cb1c4ee0 Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 29 Oct 2022 15:50:45 +0600 Subject: [PATCH 13/48] =?UTF-8?q?=F0=9F=91=BE=20smth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/05-data-types/07-map-set/article.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/05-data-types/07-map-set/article.md b/1-js/05-data-types/07-map-set/article.md index 15af9a265..5f1db921b 100644 --- a/1-js/05-data-types/07-map-set/article.md +++ b/1-js/05-data-types/07-map-set/article.md @@ -14,13 +14,13 @@ But that's not enough for real life. That's why `Map` and `Set` also exist. Methods and properties are: -- [`new Map()`](mdn:js/Map/Map) -- creates the map. -- [`map.set(key, value)`](mdn:js/Map/set) -- stores the value by the key. -- [`map.get(key)`](mdn:js/Map/get) -- returns the value by the key, `undefined` if `key` doesn't exist in map. -- [`map.has(key)`](mdn:js/Map/has) -- returns `true` if the `key` exists, `false` otherwise. -- [`map.delete(key)`](mdn:js/Map/delete) -- removes the value by the key. -- [`map.clear()`](mdn:js/Map/clear) -- removes everything from the map. -- [`map.size`](mdn:js/Map/size) -- returns the current element count. +- [`new Map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/Map) -- creates the map. +- [`map.set(key, value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set) -- stores the value by the key. +- [`map.get(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) -- returns the value by the key, `undefined` if `key` doesn't exist in map. +- [`map.has(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has) -- returns `true` if the `key` exists, `false` otherwise. +- [`map.delete(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete) -- removes the value by the key. +- [`map.clear()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear) -- removes everything from the map. +- [`map.size`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size) -- returns the current element count. For instance: @@ -104,9 +104,9 @@ map.set('1', 'str1') For looping over a `map`, there are 3 methods: -- [`map.keys()`](mdn:js/Map/keys) -- returns an iterable for keys, -- [`map.values()`](mdn:js/Map/values) -- returns an iterable for values, -- [`map.entries()`](mdn:js/Map/entries) -- returns an iterable for entries `[key, value]`, it's used by default in `for..of`. +- [`map.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys) -- returns an iterable for keys, +- [`map.values()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values) -- returns an iterable for values, +- [`map.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries) -- returns an iterable for entries `[key, value]`, it's used by default in `for..of`. For instance: @@ -232,7 +232,7 @@ That's the same, because `Object.fromEntries` expects an iterable object as the ## Set -A [`Set`](mdn:js/Set) is a special type collection - "set of values" (without keys), where each value may occur only once. +A [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) is a special type collection - "set of values" (without keys), where each value may occur only once. Its main methods are: From 78a956600b9e3d95661baca968de99cdc8d18696 Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 29 Oct 2022 16:00:37 +0600 Subject: [PATCH 14/48] =?UTF-8?q?=F0=9F=91=BE=20smth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/05-data-types/07-map-set/article.md | 54 ++++++++++++------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/1-js/05-data-types/07-map-set/article.md b/1-js/05-data-types/07-map-set/article.md index 5f1db921b..0fd68a703 100644 --- a/1-js/05-data-types/07-map-set/article.md +++ b/1-js/05-data-types/07-map-set/article.md @@ -10,7 +10,7 @@ But that's not enough for real life. That's why `Map` and `Set` also exist. ## Map -[Map](mdn:js/Map) is a collection of keyed data items, just like an `Object`. But the main difference is that `Map` allows keys of any type. +[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) is a collection of keyed data items, just like an `Object`. But the main difference is that `Map` allows keys of any type. Methods and properties are: @@ -161,7 +161,7 @@ let map = new Map([ alert( map.get('1') ); // str1 ``` -If we have a plain object, and we'd like to create a `Map` from it, then we can use built-in method [Object.entries(obj)](mdn:js/Object/entries) that returns an array of key/value pairs for an object exactly in that format. +If we have a plain object, and we'd like to create a `Map` from it, then we can use built-in method [Object.entries(obj)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) that returns an array of key/value pairs for an object exactly in that format. So we can create a map from an object like this: @@ -236,12 +236,12 @@ A [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glob Its main methods are: -- [`new Set([iterable])`](mdn:js/Set/Set) -- creates the set, and if an `iterable` object is provided (usually an array), copies values from it into the set. -- [`set.add(value)`](mdn:js/Set/add) -- adds a value, returns the set itself. -- [`set.delete(value)`](mdn:js/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. -- [`set.has(value)`](mdn:js/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. -- [`set.clear()`](mdn:js/Set/clear) -- removes everything from the set. -- [`set.size`](mdn:js/Set/size) -- is the elements count. +- [`new Set([iterable])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set) -- creates the set, and if an `iterable` object is provided (usually an array), copies values from it into the set. +- [`set.add(value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add) -- adds a value, returns the set itself. +- [`set.delete(value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. +- [`set.has(value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. +- [`set.clear()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear) -- removes everything from the set. +- [`set.size`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/size) -- is the elements count. The main feature is that repeated calls of `set.add(value)` with the same value don't do anything. That's the reason why each value appears in a `Set` only once. @@ -271,7 +271,7 @@ for (let user of set) { } ``` -The alternative to `Set` could be an array of users, and the code to check for duplicates on every insertion using [arr.find](mdn:js/Array/find). But the performance would be much worse, because this method walks through the whole array checking every element. `Set` is much better optimized internally for uniqueness checks. +The alternative to `Set` could be an array of users, and the code to check for duplicates on every insertion using [arr.find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find). But the performance would be much worse, because this method walks through the whole array checking every element. `Set` is much better optimized internally for uniqueness checks. ## Iteration over Set @@ -294,38 +294,38 @@ That's for compatibility with `Map` where the callback passed `forEach` has thre The same methods `Map` has for iterators are also supported: -- [`set.keys()`](mdn:js/Set/keys) -- returns an iterable object for values, -- [`set.values()`](mdn:js/Set/values) -- same as `set.keys()`, for compatibility with `Map`, -- [`set.entries()`](mdn:js/Set/entries) -- returns an iterable object for entries `[value, value]`, exists for compatibility with `Map`. +- [`set.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/keys) -- returns an iterable object for values, +- [`set.values()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values) -- same as `set.keys()`, for compatibility with `Map`, +- [`set.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries) -- returns an iterable object for entries `[value, value]`, exists for compatibility with `Map`. ## Summary -[`Map`](mdn:js/Map) -- is a collection of keyed values. +[`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) -- is a collection of keyed values. Methods and properties: -- [`new Map([iterable])`](mdn:js/Map/Map) -- creates the map, with optional `iterable` (e.g. array) of `[key,value]` pairs for initialization. -- [`map.set(key, value)`](mdn:js/Map/set) -- stores the value by the key, returns the map itself. -- [`map.get(key)`](mdn:js/Map/get) -- returns the value by the key, `undefined` if `key` doesn't exist in map. -- [`map.has(key)`](mdn:js/Map/has) -- returns `true` if the `key` exists, `false` otherwise. -- [`map.delete(key)`](mdn:js/Map/delete) -- removes the value by the key, returns `true` if `key` existed at the moment of the call, otherwise `false`. -- [`map.clear()`](mdn:js/Map/clear) -- removes everything from the map. -- [`map.size`](mdn:js/Map/size) -- returns the current element count. +- [`new Map([iterable])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/Map) -- creates the map, with optional `iterable` (e.g. array) of `[key,value]` pairs for initialization. +- [`map.set(key, value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set) -- stores the value by the key, returns the map itself. +- [`map.get(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) -- returns the value by the key, `undefined` if `key` doesn't exist in map. +- [`map.has(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has) -- returns `true` if the `key` exists, `false` otherwise. +- [`map.delete(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete) -- removes the value by the key, returns `true` if `key` existed at the moment of the call, otherwise `false`. +- [`map.clear()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear) -- removes everything from the map. +- [`map.size`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size) -- returns the current element count. The differences from a regular `Object`: - Any keys, objects can be keys. - Additional convenient methods, the `size` property. -[`Set`](mdn:js/Set) -- is a collection of unique values. +[`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) -- is a collection of unique values. Methods and properties: -- [`new Set([iterable])`](mdn:js/Set/Set) -- creates the set, with optional `iterable` (e.g. array) of values for initialization. -- [`set.add(value)`](mdn:js/Set/add) -- adds a value (does nothing if `value` exists), returns the set itself. -- [`set.delete(value)`](mdn:js/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. -- [`set.has(value)`](mdn:js/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. -- [`set.clear()`](mdn:js/Set/clear) -- removes everything from the set. -- [`set.size`](mdn:js/Set/size) -- is the elements count. +- [`new Set([iterable])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set) -- creates the set, with optional `iterable` (e.g. array) of values for initialization. +- [`set.add(value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add) -- adds a value (does nothing if `value` exists), returns the set itself. +- [`set.delete(value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete) -- removes the value, returns `true` if `value` existed at the moment of the call, otherwise `false`. +- [`set.has(value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has) -- returns `true` if the value exists in the set, otherwise `false`. +- [`set.clear()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear) -- removes everything from the set. +- [`set.size`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/size) -- is the elements count. Iteration over `Map` and `Set` is always in the insertion order, so we can't say that these collections are unordered, but we can't reorder elements or directly get an element by its number. From 9e08049bd8cc1304d5baaa58cd120a6702b0deb3 Mon Sep 17 00:00:00 2001 From: Lavrentiy Rubtsov Date: Sat, 29 Oct 2022 16:02:43 +0600 Subject: [PATCH 15/48] =?UTF-8?q?=F0=9F=91=BE=20smth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../08-weakmap-weakset/article.md | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/1-js/05-data-types/08-weakmap-weakset/article.md b/1-js/05-data-types/08-weakmap-weakset/article.md index bcf9e0fa3..ecb391f23 100644 --- a/1-js/05-data-types/08-weakmap-weakset/article.md +++ b/1-js/05-data-types/08-weakmap-weakset/article.md @@ -1,8 +1,10 @@ + # WeakMap and WeakSet As we know from the chapter , JavaScript engine keeps a value in memory while it is "reachable" and can potentially be used. For instance: + ```js let john = { name: "John" }; @@ -54,13 +56,13 @@ john = null; // overwrite the reference */!* ``` -[`WeakMap`](mdn:js/WeakMap) is fundamentally different in this aspect. It doesn't prevent garbage-collection of key objects. +[`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) is fundamentally different in this aspect. It doesn't prevent garbage-collection of key objects. Let's see what it means on examples. ## WeakMap -The first difference between [`Map`](mdn:js/Map) and [`WeakMap`](mdn:js/WeakMap) is that keys must be objects, not primitive values: +The first difference between [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) and [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) is that keys must be objects, not primitive values: ```js run let weakMap = new WeakMap(); @@ -94,10 +96,10 @@ Compare it with the regular `Map` example above. Now if `john` only exists as th `WeakMap` has only the following methods: -- [`weakMap.set(key, value)`](mdn:js/WeakMap/set) -- [`weakMap.get(key)`](mdn:js/WeakMap/get) -- [`weakMap.delete(key)`](mdn:js/WeakMap/delete) -- [`weakMap.has(key)`](mdn:js/WeakMap/has) +- [`weakMap.set(key, value)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set) +- [`weakMap.get(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get) +- [`weakMap.delete(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete) +- [`weakMap.has(key)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has) Why such a limitation? That's for technical reasons. If an object has lost all other references (like `john` in the code above), then it is to be garbage-collected automatically. But technically it's not exactly specified *when the cleanup happens*. @@ -242,11 +244,11 @@ obj = null; ## WeakSet -[`WeakSet`](mdn:js/WeakSet) behaves similarly: +[`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) behaves similarly: - It is analogous to `Set`, but we may only add objects to `WeakSet` (not primitives). - An object exists in the set while it is reachable from somewhere else. -- Like `Set`, it supports [`add`](mdn:js/Weakset/add), [`has`](mdn:js/Weakset/has) and [`delete`](mdn:js/Weakset/delete), but not `size`, `keys()` and no iterations. +- Like `Set`, it supports [`add`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Weakset/add), [`has`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Weakset/has) and [`delete`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Weakset/delete), but not `size`, `keys()` and no iterations. Being "weak", it also serves as additional storage. But not for arbitrary data, rather for "yes/no" facts. A membership in `WeakSet` may mean something about the object. @@ -280,9 +282,9 @@ The most notable limitation of `WeakMap` and `WeakSet` is the absence of iterati ## Summary -[`WeakMap`](mdn:js/WeakMap) is `Map`-like collection that allows only objects as keys and removes them together with associated value once they become inaccessible by other means. +[`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) is `Map`-like collection that allows only objects as keys and removes them together with associated value once they become inaccessible by other means. -[`WeakSet`](mdn:js/WeakSet) is `Set`-like collection that stores only objects and removes them once they become inaccessible by other means. +[`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) is `Set`-like collection that stores only objects and removes them once they become inaccessible by other means. Their main advantages are that they have weak reference to objects, so they can easily be removed by garbage collector. From 1bda839a94308931170fd088fb5986ebe30e176d Mon Sep 17 00:00:00 2001 From: LeviDing Date: Sun, 30 Oct 2022 15:10:14 +0800 Subject: [PATCH 16/48] fix: typo getRangesAt to getRangeAt --- 2-ui/99-ui-misc/02-selection-range/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-ui/99-ui-misc/02-selection-range/article.md b/2-ui/99-ui-misc/02-selection-range/article.md index 9d6bb9c93..819bcba29 100644 --- a/2-ui/99-ui-misc/02-selection-range/article.md +++ b/2-ui/99-ui-misc/02-selection-range/article.md @@ -408,7 +408,7 @@ From – To There are two approaches to copying the selected content: 1. We can use `document.getSelection().toString()` to get it as text. -2. Otherwise, to copy the full DOM, e.g. if we need to keep formatting, we can get the underlying ranges with `getRangesAt(...)`. A `Range` object, in turn, has `cloneContents()` method that clones its content and returns as `DocumentFragment` object, that we can insert elsewhere. +2. Otherwise, to copy the full DOM, e.g. if we need to keep formatting, we can get the underlying ranges with `getRangeAt(...)`. A `Range` object, in turn, has `cloneContents()` method that clones its content and returns as `DocumentFragment` object, that we can insert elsewhere. Here's the demo of copying the selected content both as text and as DOM nodes: From 55b6c5e1095d66129a40dd44e3b2fc6a416c859d Mon Sep 17 00:00:00 2001 From: nikolai-chernolutskii <93830967+nikolai-chernolutskii@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:36:06 +0200 Subject: [PATCH 17/48] Update article.md correct misprint: udefined => undefined --- 1-js/02-first-steps/12-nullish-coalescing-operator/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/12-nullish-coalescing-operator/article.md b/1-js/02-first-steps/12-nullish-coalescing-operator/article.md index 7dbf1835f..b2bc64f83 100644 --- a/1-js/02-first-steps/12-nullish-coalescing-operator/article.md +++ b/1-js/02-first-steps/12-nullish-coalescing-operator/article.md @@ -37,7 +37,7 @@ Here's the example with `user` assigned to a name: ```js run let user = "John"; -alert(user ?? "Anonymous"); // John (user is not null/udefined) +alert(user ?? "Anonymous"); // John (user is not null/undefined) ``` We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`. From 588117e310fc3567047c99c37f5a35fe6d7bc9a6 Mon Sep 17 00:00:00 2001 From: Alexandre888 Date: Sun, 30 Oct 2022 22:47:58 +0200 Subject: [PATCH 18/48] Update index.html --- .../1-animate-logo-css/solution.view/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/7-animation/2-css-animations/1-animate-logo-css/solution.view/index.html b/7-animation/2-css-animations/1-animate-logo-css/solution.view/index.html index 4e90e2478..17d5b51d8 100644 --- a/7-animation/2-css-animations/1-animate-logo-css/solution.view/index.html +++ b/7-animation/2-css-animations/1-animate-logo-css/solution.view/index.html @@ -27,9 +27,9 @@