Skip to content

Commit 75b3067

Browse files
authored
Merge pull request #194 from javascript-tutorial/sync-99e59ba6
Sync with upstream @ 99e59ba
2 parents 11d3813 + af4f738 commit 75b3067

File tree

26 files changed

+53
-54
lines changed

26 files changed

+53
-54
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 @@ Para que possamos visualizar erros e obter muitas outras informações úteis so
88

99
A maioria dos desenvolvedores escolhem o Chrome ou o Firefox para o desenvolvimento porque esses navegadores têm as melhores ferramentas de desenvolvedor. Outros navegadores também fornecem ferramentas de desenvolvedor, às vezes com recursos especiais, mas geralmente estão jogando "catch-up" no Chrome ou Firefox. Assim, a maioria dos desenvolvedores tem um navegador "favorito" e muda para outros se um problema é específico do navegador.
1010

11-
As ferramentas do desenvolvedor são potentes; elas têm muitos recursos. Para começar, vamos aprender como abri-las, olhar para erros e executar comandos JavaScript.
11+
As ferramentas do desenvolvedor são potentes; elas têm muitos recursos. Para começar, vamos aprender como as abrir, olhar para erros e executar comandos JavaScript.
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
@@ -145,7 +145,7 @@ loadScript('/my/script.js', function(script) {
145145
});
146146
*/!*
147147

148-
})
148+
});
149149

150150
});
151151
```
@@ -222,7 +222,7 @@ loadScript('1.js', function(error, script) {
222222
});
223223

224224
}
225-
})
225+
});
226226
}
227227
});
228228
```
@@ -255,7 +255,7 @@ loadScript('1.js', function(error, script) {
255255
}
256256
});
257257
}
258-
})
258+
});
259259
}
260260
});
261261
-->
@@ -295,7 +295,7 @@ function step3(error, script) {
295295
} else {
296296
// ...continue after all scripts are loaded (*)
297297
}
298-
};
298+
}
299299
```
300300

301301
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
@@ -315,7 +315,7 @@ fetch('/article/promise-chaining/user.json')
315315
*/!*
316316
}, 3000);
317317
}))
318-
// disparado após 3 segundoss
318+
// disparado após 3 segundos
319319
.then(githubUser => alert(`Finalizou exibição de ${githubUser.name}`));
320320
```
321321

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,14 @@ So for each promise we get its status and `value/error`.
226226
If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
227227

228228
```js
229-
if(!Promise.allSettled) {
230-
Promise.allSettled = function(promises) {
231-
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
232-
status: 'fulfilled',
233-
value
234-
}), reason => ({
235-
status: 'rejected',
236-
reason
237-
}))));
229+
if (!Promise.allSettled) {
230+
const rejectHandler = reason => ({ status: 'rejected', reason });
231+
232+
const resolveHandler = value => ({ status: 'fulfilled', value });
233+
234+
Promise.allSettled = function (promises) {
235+
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
236+
return Promise.all(convertedPromises);
238237
};
239238
}
240239
```

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)