Skip to content

Commit 75bad83

Browse files
authored
Improve grammar
1 parent b7ebc1b commit 75bad83

File tree

1 file changed

+12
-12
lines changed
  • 1-js/05-data-types/10-destructuring-assignment

1 file changed

+12
-12
lines changed

1-js/05-data-types/10-destructuring-assignment/article.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ However, when we pass these to a function, we may not need all of it. The functi
99

1010
*Destructuring assignment* is a special syntax that allows us to "unpack" arrays or objects into a bunch of variables, as sometimes that's more convenient.
1111

12-
Destructuring also works great with complex functions that have a lot of parameters, default values, and so on. Soon we'll see that.
12+
Destructuring also works well with complex functions that have a lot of parameters, default values, and so on. Soon we'll see that.
1313

1414
## Array destructuring
1515

1616
Here's an example of how an array is destructured into variables:
1717

1818
```js
19-
// we have an array with the name and surname
19+
// we have an array with a name and surname
2020
let arr = ["John", "Smith"]
2121

2222
*!*
@@ -40,10 +40,10 @@ alert(firstName); // John
4040
alert(surname); // Smith
4141
```
4242

43-
As you can see, the syntax is simple. There are several peculiar details though. Let's see more examples, to better understand it.
43+
As you can see, the syntax is simple. There are several peculiar details though. Lets see more examples to understand it better.
4444

4545
````smart header="\"Destructuring\" does not mean \"destructive\"."
46-
It's called "destructuring assignment," because it "destructurizes" by copying items into variables. But the array itself is not modified.
46+
It's called "destructuring assignment," because it "destructurizes" by copying items into variables. However, the array itself is not modified.
4747

4848
It's just a shorter way to write:
4949
```js
@@ -65,7 +65,7 @@ let [firstName, , title] = ["Julius", "Caesar", "Consul", "of the Roman Republic
6565
alert( title ); // Consul
6666
```
6767

68-
In the code above, the second element of the array is skipped, the third one is assigned to `title`, and the rest of the array items is also skipped (as there are no variables for them).
68+
In the code above, the second element of the array is skipped, the third one is assigned to `title`, and the rest of the array items are also skipped (as there are no variables for them).
6969
````
7070

7171
````smart header="Works with any iterable on the right-side"
@@ -95,17 +95,17 @@ alert(user.surname); // Smith
9595
````
9696

9797
````smart header="Looping with .entries()"
98-
In the previous chapter we saw the [Object.entries(obj)](mdn:js/Object/entries) method.
98+
In the previous chapter, we saw the [Object.entries(obj)](mdn:js/Object/entries) method.
9999

100-
We can use it with destructuring to loop over keys-and-values of an object:
100+
We can use it with destructuring to loop over the keys-and-values of an object:
101101

102102
```js run
103103
let user = {
104104
name: "John",
105105
age: 30
106106
};
107107

108-
// loop over keys-and-values
108+
// loop over the keys-and-values
109109
*!*
110110
for (let [key, value] of Object.entries(user)) {
111111
*/!*
@@ -169,7 +169,7 @@ If we'd like also to gather all that follows -- we can add one more parameter th
169169
let [name1, name2, *!*...rest*/!*] = ["Julius", "Caesar", *!*"Consul", "of the Roman Republic"*/!*];
170170

171171
*!*
172-
// rest is array of items, starting from the 3rd one
172+
// rest is an array of items, starting from the 3rd one
173173
alert(rest[0]); // Consul
174174
alert(rest[1]); // of the Roman Republic
175175
alert(rest.length); // 2
@@ -187,7 +187,7 @@ let [name1, name2, *!*...titles*/!*] = ["Julius", "Caesar", "Consul", "of the Ro
187187

188188
### Default values
189189

190-
If the array is shorter than the list of variables at the left, there'll be no errors. Absent values are considered undefined:
190+
If the array is shorter than the list of variables on the left, there will be no errors. Absent values are considered undefined:
191191

192192
```js run
193193
*!*
@@ -418,7 +418,7 @@ alert( title ); // Menu
418418

419419
## Nested destructuring
420420

421-
If an object or an array contain other nested objects and arrays, we can use more complex left-side patterns to extract deeper portions.
421+
If an object or an array contains other nested objects and arrays, we can use more complex left-side patterns to extract deeper portions.
422422

423423
In the code below `options` has another object in the property `size` and an array in the property `items`. The pattern on the left side of the assignment has the same structure to extract values from them:
424424

@@ -461,7 +461,7 @@ Note that there are no variables for `size` and `items`, as we take their conten
461461

462462
There are times when a function has many parameters, most of which are optional. That's especially true for user interfaces. Imagine a function that creates a menu. It may have a width, a height, a title, items list and so on.
463463

464-
Here's a bad way to write such function:
464+
Here's a bad way to write such a function:
465465

466466
```js
467467
function showMenu(title = "Untitled", width = 200, height = 100, items = []) {

0 commit comments

Comments
 (0)