Skip to content

Commit 12ca5f5

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-99e59ba6
2 parents 3085e54 + 99e59ba commit 12ca5f5

File tree

27 files changed

+54
-55
lines changed

27 files changed

+54
-55
lines changed

1-js/01-getting-started/4-devtools/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To see errors and get a lot of other useful information about scripts, "develope
88

99
Most developers lean towards Chrome or Firefox for development because those browsers have the best developer tools. Other browsers also provide developer tools, sometimes with special features, but are usually playing "catch-up" to Chrome or Firefox. So most developers have a "favorite" browser and switch to others if a problem is browser-specific.
1010

11-
Developer tools are potent; they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
11+
Developer tools are potent, they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
1212

1313
## Google Chrome
1414

1-js/04-object-basics/07-optional-chaining/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The optional chaining `?.` stops the evaluation if the part before `?.` is `unde
8080

8181
In other words, `value?.prop`:
8282
- is the same as `value.prop` if `value` exists,
83-
- otherwise (when `value` is `undefined/null`) it returns that `value`.
83+
- otherwise (when `value` is `undefined/null`) it returns `undefined`.
8484

8585
Here's the safe way to access `user.address.street` using `?.`:
8686

1-js/05-data-types/05-array-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ These methods are the most used ones, they cover 99% of use cases. But there are
743743

744744
The function `fn` is called on each element of the array similar to `map`. If any/all results are `true`, returns `true`, otherwise `false`.
745745

746-
These methods behave sort of like `||` and `&&` operators: if `fn` returns a truthy value, `arr.some()` immediately returns `true` and stops iterating over the rest items; if `fn` returns a falsy value, `arr.every()` immediately returns `false` and stops iterating over the rest items as well.
746+
These methods behave sort of like `||` and `&&` operators: if `fn` returns a truthy value, `arr.some()` immediately returns `true` and stops iterating over the rest items; if `fn` returns a falsy value, `arr.every()` immediately returns `false` and stops iterating over the rest items as well.
747747

748748
We can use `every` to compare arrays:
749749
```js run

1-js/06-advanced-functions/01-recursion/02-factorial/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
By definition, a factorial is `n!` can be written as `n * (n-1)!`.
1+
By definition, a factorial `n!` can be written as `n * (n-1)!`.
22

33
In other words, the result of `factorial(n)` can be calculated as `n` multiplied by the result of `factorial(n-1)`. And the call for `n-1` can recursively descend lower, and lower, till `1`.
44

1-js/06-advanced-functions/01-recursion/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ We can sketch it as:
132132
</li>
133133
</ul>
134134
135-
That's when the function starts to execute. The condition `n == 1` is false, so the flow continues into the second branch of `if`:
135+
That's when the function starts to execute. The condition `n == 1` is falsy, so the flow continues into the second branch of `if`:
136136
137137
```js run
138138
function pow(x, n) {
@@ -188,7 +188,7 @@ The new current execution context is on top (and bold), and previous remembered
188188
When we finish the subcall -- it is easy to resume the previous context, because it keeps both variables and the exact place of the code where it stopped.
189189
190190
```smart
191-
Here in the picture we use the word "line", as our example there's only one subcall in line, but generally a single line of code may contain multiple subcalls, like `pow(…) + pow(…) + somethingElse(…)`.
191+
Here in the picture we use the word "line", as in our example there's only one subcall in line, but generally a single line of code may contain multiple subcalls, like `pow(…) + pow(…) + somethingElse(…)`.
192192
193193
So it would be more precise to say that the execution resumes "immediately after the subcall".
194194
```

1-js/11-async/01-callbacks/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ loadScript('/my/script.js', function(script) {
146146
});
147147
*/!*
148148

149-
})
149+
});
150150

151151
});
152152
```
@@ -223,7 +223,7 @@ loadScript('1.js', function(error, script) {
223223
});
224224

225225
}
226-
})
226+
});
227227
}
228228
});
229229
```
@@ -256,7 +256,7 @@ loadScript('1.js', function(error, script) {
256256
}
257257
});
258258
}
259-
})
259+
});
260260
}
261261
});
262262
-->
@@ -296,7 +296,7 @@ function step3(error, script) {
296296
} else {
297297
// ...continue after all scripts are loaded (*)
298298
}
299-
};
299+
}
300300
```
301301

302302
See? It does the same, and there's no deep nesting now because we made every action a separate top-level function.

1-js/11-async/03-promise-chaining/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fetch('/article/promise-chaining/user.json')
265265

266266
Now let's do something with the loaded user.
267267

268-
For instance, we can make one more requests to GitHub, load the user profile and show the avatar:
268+
For instance, we can make one more request to GitHub, load the user profile and show the avatar:
269269

270270
```js run
271271
// Make a request for user.json

1-js/11-async/05-promise-api/article.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,14 @@ So for each promise we get its status and `value/error`.
176176
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
177177
178178
```js
179-
if(!Promise.allSettled) {
180-
Promise.allSettled = function(promises) {
181-
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
182-
status: 'fulfilled',
183-
value
184-
}), reason => ({
185-
status: 'rejected',
186-
reason
187-
}))));
179+
if (!Promise.allSettled) {
180+
const rejectHandler = reason => ({ status: 'rejected', reason });
181+
182+
const resolveHandler = value => ({ status: 'fulfilled', value });
183+
184+
Promise.allSettled = function (promises) {
185+
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
186+
return Promise.all(convertedPromises);
188187
};
189188
}
190189
```

1-js/11-async/06-promisify/article.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ Here it is:
3636
let loadScriptPromise = function(src) {
3737
return new Promise((resolve, reject) => {
3838
loadScript(src, (err, script) => {
39-
if (err) reject(err)
39+
if (err) reject(err);
4040
else resolve(script);
4141
});
42-
})
43-
}
42+
});
43+
};
4444

4545
// usage:
4646
// loadScriptPromise('path/script.js').then(...)
@@ -71,7 +71,7 @@ function promisify(f) {
7171
f.call(this, ...args); // call the original function
7272
});
7373
};
74-
};
74+
}
7575

7676
// usage:
7777
let loadScriptPromise = promisify(loadScript);
@@ -82,7 +82,7 @@ The code may look a bit complex, but it's essentially the same that we wrote abo
8282

8383
A call to `promisify(f)` returns a wrapper around `f` `(*)`. That wrapper returns a promise and forwards the call to the original `f`, tracking the result in the custom callback `(**)`.
8484

85-
Here, `promisiefy` assumes that the original function expects a callback with exactly two arguments `(err, result)`. That's what we encounter most often. Then our custom callback is in exactly the right format, and `promisify` works great for such a case.
85+
Here, `promisify` assumes that the original function expects a callback with exactly two arguments `(err, result)`. That's what we encounter most often. Then our custom callback is in exactly the right format, and `promisify` works great for such a case.
8686

8787
But what if the original `f` expects a callback with more arguments `callback(err, res1, res2, ...)`?
8888

@@ -110,11 +110,11 @@ function promisify(f, manyArgs = false) {
110110
f.call(this, ...args);
111111
});
112112
};
113-
};
113+
}
114114

115115
// usage:
116116
f = promisify(f, true);
117-
f(...).then(arrayOfResults => ..., err => ...)
117+
f(...).then(arrayOfResults => ..., err => ...);
118118
```
119119
120120
As you can see it's essentially the same as above, but `resolve` is called with only one or all arguments depending on whether `manyArgs` is truthy.

1-js/11-async/08-async-await/01-rewrite-async/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function loadJson(url) {
1212
} else {
1313
throw new Error(response.status);
1414
}
15-
})
15+
});
1616
}
1717

1818
loadJson('no-such-user.json')

0 commit comments

Comments
 (0)