Skip to content

Commit 2b04aec

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-69893128
2 parents 97fd3dd + 6989312 commit 2b04aec

File tree

14 files changed

+46
-18
lines changed

14 files changed

+46
-18
lines changed

1-js/01-getting-started/1-intro/article.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ For instance, in-browser JavaScript is able to:
5959

6060
## What CAN'T in-browser JavaScript do?
6161

62-
JavaScript's abilities in the browser are limited for the sake of the user's safety. The aim is to prevent an evil webpage from accessing private information or harming the user's data.
62+
JavaScript's abilities in the browser are limited for the sake of a user's safety. The aim is to prevent an evil webpage from accessing private information or harming the user's data.
6363

6464
Examples of such restrictions include:
6565

@@ -86,7 +86,7 @@ There are at least *three* great things about JavaScript:
8686
```compare
8787
+ Full integration with HTML/CSS.
8888
+ Simple things are done simply.
89-
+ Support by all major browsers and enabled by default.
89+
+ Supported by all major browsers and enabled by default.
9090
```
9191
JavaScript is the only browser technology that combines these three things.
9292

@@ -118,5 +118,5 @@ There are more. Of course, even if we use one of transpiled languages, we should
118118
## Summary
119119

120120
- JavaScript was initially created as a browser-only language, but it is now used in many other environments as well.
121-
- Today, JavaScript has a unique position as the most widely-adopted browser language with full integration in HTML/CSS.
121+
- Today, JavaScript has a unique position as the most widely-adopted browser language, fully integrated with HTML/CSS.
122122
- There are many languages that get "transpiled" to JavaScript and provide certain features. It is recommended to take a look at them, at least briefly, after mastering JavaScript.

1-js/06-advanced-functions/03-closure/9-sort-by-field/_js.view/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("byField", function(){
2323
{ name: "John", age: 20, surname: "Johnson"},
2424
];
2525
let ageSortedAnswer = users.sort(byField("age"));
26-
assert.deepEqual(ageSortedKey, ageSortedKey);
26+
assert.deepEqual(ageSortedKey, ageSortedAnswer);
2727
});
2828

2929
it("sorts users by surname", function(){

1-js/06-advanced-functions/10-bind/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ let user = {
187187

188188
let say = user.say.bind(user);
189189

190-
say("Hello"); // Hello, John ("Hello" argument is passed to say)
191-
say("Bye"); // Bye, John ("Bye" is passed to say)
190+
say("Hello"); // Hello, John! ("Hello" argument is passed to say)
191+
say("Bye"); // Bye, John! ("Bye" is passed to say)
192192
```
193193

194194
````smart header="Convenience method: `bindAll`"

1-js/09-classes/06-instanceof/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The algorithm of `obj instanceof Class` works roughly as follows:
9393
alert(rabbit instanceof Animal); // true
9494
*/!*
9595
96-
// rabbit.__proto__ === Rabbit.prototype
96+
// rabbit.__proto__ === Animal.prototype (no match)
9797
*!*
9898
// rabbit.__proto__.__proto__ === Animal.prototype (match!)
9999
*/!*

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The idea is that the result is passed through the chain of `.then` handlers.
3737
Here the flow is:
3838
1. The initial promise resolves in 1 second `(*)`,
3939
2. Then the `.then` handler is called `(**)`, which in turn creates a new promise (resolved with `2` value).
40-
3. The next `then` `(***)` gets the result of the previous one, processes it (doubles) and passes the next handler.
40+
3. The next `then` `(***)` gets the result of the previous one, processes it (doubles) and passes it to the next handler.
4141
4. ...and so on.
4242

4343
As the result is passed along the chain of handlers, we can see a sequence of `alert` calls: `1` -> `2` -> `4`.

1-js/11-async/08-async-await/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ The `async` keyword before a function has two effects:
303303
304304
The `await` keyword before a promise makes JavaScript wait until that promise settles, and then:
305305
306-
1. If it's an error, the exception is generated — same as if `throw error` were called at that very place.
306+
1. If it's an error, an exception is generated — same as if `throw error` were called at that very place.
307307
2. Otherwise, it returns the result.
308308
309309
Together they provide a great framework to write asynchronous code that is easy to both read and write.

1-js/13-modules/01-modules-intro/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Compare it to non-module scripts, where `this` is a global object:
261261
262262
There are also several browser-specific differences of scripts with `type="module"` compared to regular ones.
263263
264-
You may want skip this section for now if you're reading for the first time, or if you don't use JavaScript in a browser.
264+
You may want to skip this section for now if you're reading for the first time, or if you don't use JavaScript in a browser.
265265
266266
### Module scripts are deferred
267267

2-ui/1-document/05-basic-dom-node-properties/article.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ The classes are:
2525
- [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement) -- the class for `<input>` elements,
2626
- [HTMLBodyElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlbodyelement) -- the class for `<body>` elements,
2727
- [HTMLAnchorElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlanchorelement) -- the class for `<a>` elements,
28-
- ...and so on, each tag has its own class that may provide specific properties and methods.
28+
- ...and so on.
29+
30+
There are many other tags with their own classes that may specific properties and methods, while some elements, such as `<span>`, `<section>`, `<article>` do not have any specific properties, so they are instances of `HTMLElement` class.
2931

3032
So, the full set of properties and methods of a given node comes as the result of the inheritance.
3133

@@ -128,7 +130,7 @@ For instance:
128130
129131
```html run
130132
<body>
131-
<script>
133+
<script>
132134
let elem = document.body;
133135
134136
// let's examine what it is?

2-ui/1-document/09-size-and-scroll/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function isHidden(elem) {
116116
}
117117
```
118118
119-
Please note that such `isHidden` returns `true` for elements that are on-screen, but have zero sizes (like an empty `<div>`).
119+
Please note that such `isHidden` returns `true` for elements that are on-screen, but have zero sizes.
120120
````
121121

122122
## clientTop/Left

2-ui/2-events/01-introduction-browser-events/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ button.onclick = sayThanks;
160160
button.onclick = sayThanks();
161161
```
162162

163-
If we add parentheses, then `sayThanks()` becomes is a function call. So the last line actually takes the *result* of the function execution, that is `undefined` (as the function returns nothing), and assigns it to `onclick`. That doesn't work.
163+
If we add parentheses, then `sayThanks()` becomes a function call. So the last line actually takes the *result* of the function execution, that is `undefined` (as the function returns nothing), and assigns it to `onclick`. That doesn't work.
164164

165165
...On the other hand, in the markup we do need the parentheses:
166166

2-ui/3-event-details/7-keyboard-events/keyboard-dump.view/script.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ let lastTime = Date.now();
55
function handle(e) {
66
if (form.elements[e.type + 'Ignore'].checked) return;
77

8+
area.scrollTop = 1e6;
9+
810
let text = e.type +
911
' key=' + e.key +
1012
' code=' + e.code +

2-ui/5-loading/01-onload-ondomcontentloaded/article.md

+20
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,26 @@ window.onbeforeunload = function() {
185185

186186
The behavior was changed, because some webmasters abused this event handler by showing misleading and annoying messages. So right now old browsers still may show it as a message, but aside of that -- there's no way to customize the message shown to the user.
187187

188+
````warn header="The `event.preventDefault()` doesn't work from a `beforeunload` handler"
189+
That may sound weird, but most browsers ignore `event.preventDefault()`.
190+
191+
Which means, following code may not work:
192+
```js run
193+
window.addEventListener("beforeunload", (event) => {
194+
// doesn't work, so this event handler doesn't do anything
195+
event.preventDefault();
196+
});
197+
```
198+
199+
Instead, in such handlers one should set `event.returnValue` to a string to get the result similar to the code above:
200+
```js run
201+
window.addEventListener("beforeunload", (event) => {
202+
// works, same as returning from window.onbeforeunload
203+
event.returnValue = "There are unsaved changes. Leave now?";
204+
});
205+
```
206+
````
207+
188208
## readyState
189209
190210
What happens if we set the `DOMContentLoaded` handler after the document is loaded?

2-ui/5-loading/02-script-async-defer/article.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ Async scripts are great when we integrate an independent third-party script into
133133
<script async src="https://google-analytics.com/analytics.js"></script>
134134
```
135135

136+
```smart header="The `async` attribute is only for external scripts"
137+
Just like `defer`, the `async` attribute is ignored if the `<script>` tag has no `src`.
138+
```
139+
136140
## Dynamic scripts
137-
141+
138142
There's one more important way of adding a script to the page.
139143
140144
We can create a script and append it to the document dynamically using JavaScript:
@@ -188,7 +192,7 @@ But there are also essential differences between them:
188192
| `async` | *Load-first order*. Their document order doesn't matter -- which loads first runs first | Irrelevant. May load and execute while the document has not yet been fully downloaded. That happens if scripts are small or cached, and the document is long enough. |
189193
| `defer` | *Document order* (as they go in the document). | Execute after the document is loaded and parsed (they wait if needed), right before `DOMContentLoaded`. |
190194

191-
In practice, `defer` is used for scripts that need the whole DOM and/or their relative execution order is important.
195+
In practice, `defer` is used for scripts that need the whole DOM and/or their relative execution order is important.
192196

193197
And `async` is used for independent scripts, like counters or ads. And their relative execution order does not matter.
194198

9-regular-expressions/07-regexp-escaping/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
As we've seen, a backslash `pattern:\` is used to denote character classes, e.g. `pattern:\d`. So it's a special character in regexps (just like in regular strings).
55

6-
There are other special characters as well, that have special meaning in a regexp. They are used to do more powerful searches. Here's a full list of them: `pattern:[ \ ^ $ . | ? * + ( )`.
6+
There are other special characters as well, that have special meaning in a regexp, such as `pattern:[ ] { } ( ) \ ^ $ . | ? * +`. They are used to do more powerful searches.
77

8-
Don't try to remember the list -- soon we'll deal with each of them separately and you'll know them by heart automatically.
8+
Don't try to remember the list -- soon we'll deal with each of them, and you'll know them by heart automatically.
99

1010
## Escaping
1111

0 commit comments

Comments
 (0)