Skip to content

Commit bbac8a5

Browse files
authored
Fix grammar and JavaScript syntax
1 parent 5ab1ce2 commit bbac8a5

File tree

1 file changed

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

1 file changed

+10
-10
lines changed

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The two most used data structures in JavaScript are `Object` and `Array`.
55
- Objects allow us to create a single entity that stores data items by key.
66
- Arrays allow us to gather data items into an ordered list.
77

8-
Although, when we pass those to a function, it may need not be an object/array as a whole. It may need individual pieces.
8+
However, when we pass those to a function, it may need not to be an object/array as a whole. It may need individual pieces.
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

@@ -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
@@ -449,7 +449,7 @@ alert(item1); // Cake
449449
alert(item2); // Donut
450450
```
451451
452-
All properties of `options` object except `extra` that is absent in the left part, are assigned to corresponding variables:
452+
All properties of `options` object except `extra` which is absent in the left part, are assigned to corresponding variables:
453453
454454
![](destructuring-complex.svg)
455455
@@ -459,17 +459,17 @@ Note that there are no variables for `size` and `items`, as we take their conten
459459
460460
## Smart function parameters
461461
462-
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.
462+
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, an item 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 = []) {
468468
// ...
469469
}
470470
```
471471
472-
In real-life, the problem is how to remember the order of arguments. Usually IDEs try to help us, especially if the code is well-documented, but still... Another problem is how to call a function when most parameters are ok by default.
472+
In real-life, the problem is how to remember the order of arguments. Usually, IDEs try to help us, especially if the code is well-documented, but still... Another problem is how to call a function when most parameters are ok by default.
473473
474474
Like this?
475475
@@ -534,7 +534,7 @@ function({
534534
})
535535
```
536536

537-
Then, for an object of parameters, there will be a variable `varName` for property `incomingProperty`, with `defaultValue` by default.
537+
Then, for an object of parameters, there will be a variable `varName` for the property `incomingProperty`, with `defaultValue` by default.
538538

539539
Please note that such destructuring assumes that `showMenu()` does have an argument. If we want all values by default, then we should specify an empty object:
540540

@@ -561,7 +561,7 @@ In the code above, the whole arguments object is `{}` by default, so there's alw
561561
- Destructuring assignment allows for instantly mapping an object or array onto many variables.
562562
- The full object syntax:
563563
```js
564-
let {prop : varName = default, ...rest} = object
564+
let {prop : varName = defaultValue, ...rest} = object
565565
```
566566

567567
This means that property `prop` should go into the variable `varName` and, if no such property exists, then the `default` value should be used.
@@ -571,9 +571,9 @@ In the code above, the whole arguments object is `{}` by default, so there's alw
571571
- The full array syntax:
572572

573573
```js
574-
let [item1 = default, item2, ...rest] = array
574+
let [item1 = defaultValue, item2, ...rest] = array
575575
```
576576

577-
The first item goes to `item1`; the second goes into `item2`, all the rest makes the array `rest`.
577+
The first item goes to `item1`; the second goes into `item2`, and all the rest makes the array `rest`.
578578

579579
- It's possible to extract data from nested arrays/objects, for that the left side must have the same structure as the right one.

0 commit comments

Comments
 (0)