You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/10-destructuring-assignment/article.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -449,7 +449,7 @@ alert(item1); // Cake
449
449
alert(item2); // Donut
450
450
```
451
451
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:
453
453
454
454

455
455
@@ -459,7 +459,7 @@ Note that there are no variables for `size` and `items`, as we take their conten
459
459
460
460
## Smart function parameters
461
461
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.
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.
473
473
474
474
Like this?
475
475
@@ -534,7 +534,7 @@ function({
534
534
})
535
535
```
536
536
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.
538
538
539
539
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:
540
540
@@ -561,7 +561,7 @@ In the code above, the whole arguments object is `{}` by default, so there's alw
561
561
- Destructuring assignment allows for instantly mapping an object or array onto many variables.
562
562
- The full object syntax:
563
563
```js
564
-
let {prop : varName =default, ...rest} = object
564
+
let {prop : varName =defaultValue, ...rest} = object
565
565
```
566
566
567
567
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
571
571
- The full array syntax:
572
572
573
573
```js
574
-
let [item1 = default, item2, ...rest] = array
574
+
let [item1 = defaultValue, item2, ...rest] = array
575
575
```
576
576
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`.
578
578
579
579
- 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