Skip to content

Commit 5cdc613

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-62299ed8
2 parents 75a7368 + 62299ed commit 5cdc613

File tree

15 files changed

+65
-21
lines changed

15 files changed

+65
-21
lines changed

1-js/02-first-steps/01-hello-world/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The `<script>` tag contains JavaScript code which is automatically executed when
4646
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
4747

4848
The `type` attribute: <code>&lt;script <u>type</u>=...&gt;</code>
49-
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic; we'll talk about modules in another part of the tutorial.
49+
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic, we'll talk about modules in another part of the tutorial.
5050

5151
The `language` attribute: <code>&lt;script <u>language</u>=...&gt;</code>
5252
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ user.likes birds = true
103103

104104
JavaScript doesn't understand that. It thinks that we address `user.likes`, and then gives a syntax error when comes across unexpected `birds`.
105105

106-
The dot requires the key to be a valid variable identifier. That implies: contains no spaces, doesn't start with a digit and doesn't include special characters (`$` и `_` are allowed).
106+
The dot requires the key to be a valid variable identifier. That implies: contains no spaces, doesn't start with a digit and doesn't include special characters (`$` and `_` are allowed).
107107

108108
There's an alternative "square bracket notation" that works with any string:
109109

1-js/05-data-types/02-number/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ Please note that an empty or a space-only string is treated as `0` in all numeri
324324

325325
```smart header="Compare with `Object.is`"
326326

327-
There is a special built-in method [Object.is](mdn:js/Object/is) that compares values like `===`, but is more reliable for two edge cases:
327+
There is a special built-in method [`Object.is`](mdn:js/Object/is) that compares values like `===`, but is more reliable for two edge cases:
328328

329329
1. It works with `NaN`: `Object.is(NaN, NaN) === true`, that's a good thing.
330330
2. Values `0` and `-0` are different: `Object.is(0, -0) === false`, technically that's true, because internally the number has a sign bit that may be different even if all other bits are zeroes.
@@ -417,7 +417,7 @@ To write numbers with many zeroes:
417417

418418
For different numeral systems:
419419

420-
- Can write numbers directly in hex (`0x`), octal (`0o`) and binary (`0b`) systems
420+
- Can write numbers directly in hex (`0x`), octal (`0o`) and binary (`0b`) systems.
421421
- `parseInt(str, base)` parses the string `str` into an integer in numeral system with given `base`, `2 ≤ base ≤ 36`.
422422
- `num.toString(base)` converts a number to a string in the numeral system with the given `base`.
423423

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ list.next.next.next = { value: 4 };
462462
list.next.next.next.next = null;
463463
```
464464
465-
Here we can even more clearer see that there are multiple objects, each one has the `value` and `next` pointing to the neighbour. The `list` variable is the first object in the chain, so following `next` pointers from it we can reach any element.
465+
Here we can even more clearly see that there are multiple objects, each one has the `value` and `next` pointing to the neighbour. The `list` variable is the first object in the chain, so following `next` pointers from it we can reach any element.
466466
467467
The list can be easily split into multiple parts and later joined back:
468468

1-js/06-advanced-functions/02-rest-parameters-spread/article.md

+45
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,51 @@ But there's a subtle difference between `Array.from(obj)` and `[...obj]`:
225225
So, for the task of turning something into an array, `Array.from` tends to be more universal.
226226
227227
228+
## Get a new copy of an object/array
229+
230+
Remember when we talked about `Object.assign()` [in the past](https://javascript.info/symbol#symbols-are-skipped-by-for-in)?
231+
232+
It is possible to do the same thing with the spread operator!
233+
234+
```
235+
let arr = [1, 2, 3];
236+
let arrCopy = [...arr]; // spread the array into a list of parameters
237+
// then put the result into a new array
238+
239+
// do the arrays have the same contents?
240+
alert(JSON.stringify(arr) === JSON.stringify(arrCopy)); // true
241+
242+
// are the arrays equal?
243+
alert(arr === arrCopy); // false (not same reference)
244+
245+
// modifying our initial array does not modify the copy:
246+
arr.push(4);
247+
alert(arr); // 1, 2, 3, 4
248+
alert(arrCopy); // 1, 2, 3
249+
```
250+
251+
Note that it is possible to do the same thing to make a copy of an object:
252+
253+
```
254+
let obj = { a: 1, b: 2, c: 3 };
255+
let objCopy = { ...obj }; // spread the object into a list of parameters
256+
// then return the result in a new object
257+
258+
// do the objects have the same contents?
259+
alert(JSON.stringify(obj) === JSON.stringify(objCopy)); // true
260+
261+
// are the objects equal?
262+
alert(obj === objCopy); // false (not same reference)
263+
264+
// modifying our initial object does not modify the copy:
265+
obj.d = 4;
266+
alert(JSON.stringify(obj)); // {"a":1,"b":2,"c":3,"d":4}
267+
alert(JSON.stringify(objCopy)); // {"a":1,"b":2,"c":3}
268+
```
269+
270+
This way of copying an object is much shorter than `let objCopy = Object.assign({}, obj);` or for an array `let arrCopy = Object.assign([], arr);` so we prefer to use it whenever we can.
271+
272+
228273
## Summary
229274
230275
When we see `"..."` in the code, it is either rest parameters or the spread syntax.

1-js/06-advanced-functions/03-closure/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Rectangles on the right-hand side demonstrate how the global Lexical Environment
200200
>>>>>>> a0bfa924a17cad8e7fee213904b27dbf57c2dbac
201201
=======
202202
1. When the script starts, the Lexical Environment is pre-populated with all declared variables.
203-
- Initially, they are in the "Uninitialized" state. That's a special internal state, it means that the engine knows about the variable, but won't allow to use it before `let`. It's almost the same as if the variable didn't exist.
203+
- Initially, they are in the "Uninitialized" state. That's a special internal state, it means that the engine knows about the variable, but it cannot be referenced until it has been declared with `let`. It's almost the same as if the variable didn't exist.
204204
2. Then `let phrase` definition appears. There's no assignment yet, so its value is `undefined`. We can use the variable since this moment.
205205
3. `phrase` is assigned a value.
206206
4. `phrase` changes the value.

1-js/08-prototypes/04-prototype-methods/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This call makes a truly exact copy of `obj`, including all properties: enumerabl
6565

6666
## Brief history
6767

68-
If we count all the ways to manage `[[Prototype]]`, there are a lot! Many ways to do the same!
68+
If we count all the ways to manage `[[Prototype]]`, there are a lot! Many ways to do the same thing!
6969

7070
Why?
7171

2-ui/1-document/11-coordinates/1-find-point-coordinates/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Outer corners
22

3-
Outer corners are basically what we get from [elem.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect).
3+
Outer corners are basically what we get from [elem.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect).
44

55
Coordinates of the upper-left corner `answer1` and the bottom-right corner `answer2`:
66

2-ui/2-events/02-bubbling-and-capturing/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ elem.addEventListener("click", e => alert(2));
204204
205205
When an event happens -- the most nested element where it happens gets labeled as the "target element" (`event.target`).
206206
207-
- Then the event moves down from the document root to `event.target`, calling handlers assigned with `addEventListener(...., true)` on the way (`true` is a shorthand for `{capture: true}`).
207+
- Then the event moves down from the document root to `event.target`, calling handlers assigned with `addEventListener(..., true)` on the way (`true` is a shorthand for `{capture: true}`).
208208
- Then handlers are called on the target element itself.
209209
- Then the event bubbles up from `event.target` up to the root, calling handlers assigned using `on<event>` and `addEventListener` without the 3rd argument or with the 3rd argument `false/{capture:false}`.
210210

2-ui/2-events/04-default-browser-action/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The property `event.defaultPrevented` is `true` if the default action was preven
113113

114114
There's an interesting use case for it.
115115

116-
You remember in the chapter <info:bubbling-and-capturing> we talked about `event.stopPropagation()` and why stopping bubbling is bad?
116+
You remember in the chapter <info:bubbling-and-capturing> we talked about `event.stopPropagation()` and why stopping bubbling is bad?
117117

118118
Sometimes we can use `event.defaultPrevented` instead, to signal other event handlers that the event was handled.
119119

2-ui/2-events/05-dispatch-events/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ For instance, here the nested `menu-open` event is processed synchronously, duri
236236
237237
document.addEventListener('menu-open', () => alert('nested'));
238238
</script>
239-
```
239+
```
240240

241241
The output order is: 1 -> nested -> 2.
242242

@@ -263,7 +263,7 @@ If we don't like it, we can either put the `dispatchEvent` (or other event-trigg
263263
264264
document.addEventListener('menu-open', () => alert('nested'));
265265
</script>
266-
```
266+
```
267267

268268
Now `dispatchEvent` runs asynchronously after the current code execution is finished, including `mouse.onclick`, so event handlers are totally separate.
269269

2-ui/3-event-details/1-mouse-events-basics/article.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ But if we track `mousedown` and `mouseup`, then we need it, because these events
6565
There are the three possible values:
6666

6767
- `event.which == 1` -- the left button
68-
- `event.which == 2` - the middle button
69-
- `event.which == 3` - the right button
68+
- `event.which == 2` -- the middle button
69+
- `event.which == 3` -- the right button
7070

7171
The middle button is somewhat exotic right now and is very rarely used.
7272

@@ -116,8 +116,7 @@ For JS-code it means that we should check `if (event.ctrlKey || event.metaKey)`.
116116
```
117117
118118
```warn header="There are also mobile devices"
119-
Keyboard combinations are good as an addition to the workflow. So that if the visitor has a
120-
keyboard -- it works. And if their device doesn't have it -- then there should be another way to do the same.
119+
Keyboard combinations are good as an addition to the workflow. So that if the visitor has a keyboard -- it works. And if their device doesn't have it -- then there should be another way to do the same.
121120
```
122121

123122
## Coordinates: clientX/Y, pageX/Y

5-network/02-formdata/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let formData = new FormData([form]);
1212

1313
If HTML `form` element is provided, it automatically captures its fields.
1414

15-
The special thing about `FormData` is that network methods, such as `fetch`, can accept a `FormData` object as a body. It's encoded and sent out with `Content-Type: form/multipart`.
15+
The special thing about `FormData` is that network methods, such as `fetch`, can accept a `FormData` object as a body. It's encoded and sent out with `Content-Type: multipart/form-data`.
1616

1717
From the server point of view, that looks like a usual form submission.
1818

@@ -81,7 +81,7 @@ for(let [name, value] of formData) {
8181

8282
## Sending a form with a file
8383

84-
The form is always sent as `Content-Type: form/multipart`, this encoding allows to send files. So, `<input type="file">` fields are sent also, similar to a usual form submission.
84+
The form is always sent as `Content-Type: multipart/form-data`, this encoding allows to send files. So, `<input type="file">` fields are sent also, similar to a usual form submission.
8585

8686
Here's an example with such form:
8787

7-animation/1-bezier-curve/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Here are some examples:
5050
## De Casteljau's algorithm
5151

5252
There's a mathematical formula for Bezier curves, but let's cover it a bit later, because
53-
[De Casteljau's algorithm](https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm) it is identical to the mathematical definition and visually shows how it is constructed.
53+
[De Casteljau's algorithm](https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm) is identical to the mathematical definition and visually shows how it is constructed.
5454

5555
First let's see the 3-points example.
5656

@@ -176,7 +176,7 @@ Instead of <code>x<sub>1</sub>, y<sub>1</sub>, x<sub>2</sub>, y<sub>2</sub>, x<s
176176
For instance, if control points are `(0,0)`, `(0.5, 1)` and `(1, 0)`, the equations become:
177177

178178
- <code>x = (1−t)<sup>2</sup> * 0 + 2(1−t)t * 0.5 + t<sup>2</sup> * 1 = (1-t)t + t<sup>2</sup> = t</code>
179-
- <code>y = (1−t)<sup>2</sup> * 0 + 2(1−t)t * 1 + t<sup>2</sup> * 0 = 2(1-t)t = –t<sup>2</sup> + 2t</code>
179+
- <code>y = (1−t)<sup>2</sup> * 0 + 2(1−t)t * 1 + t<sup>2</sup> * 0 = 2(1-t)t = –2t<sup>2</sup> + 2t</code>
180180

181181
Now as `t` runs from `0` to `1`, the set of values `(x,y)` for each `t` forms the curve for such control points.
182182

9-regular-expressions/03-regexp-unicode/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unicode: flag "u" and class \p{...}
22

3-
JavaScript uses [Unicode encoding](https://en.wikipedia.org/wiki/Unicode) for strings. Most characters are encoding with 2 bytes, but that allows to represent at most 65536 characters.
3+
JavaScript uses [Unicode encoding](https://en.wikipedia.org/wiki/Unicode) for strings. Most characters are encoded with 2 bytes, but that allows to represent at most 65536 characters.
44

55
That range is not big enough to encode all possible characters, that's why some rare characters are encoded with 4 bytes, for instance like `𝒳` (mathematical X) or `😄` (a smile), some hieroglyphs and so on.
66

0 commit comments

Comments
 (0)