Skip to content

Commit 42ca672

Browse files
authored
Merge pull request javascript-tutorial#269 from usernamehw/patch-16
Update article.md
2 parents 6353874 + 9a3580e commit 42ca672

File tree

1 file changed

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

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ let user = {
9999
100100
// loop over keys-and-values
101101
*!*
102-
for(let [key, value] of Object.entries(user)) {
102+
for (let [key, value] of Object.entries(user)) {
103103
*/!*
104104
alert(`${key}:${value}`); // name:John, then age:30
105105
}
@@ -113,7 +113,7 @@ user.set("name", "John");
113113
user.set("age", "30");
114114
115115
*!*
116-
for(let [key, value] of user.entries()) {
116+
for (let [key, value] of user.entries()) {
117117
*/!*
118118
alert(`${key}:${value}`); // name:John, then age:30
119119
}
@@ -136,7 +136,7 @@ alert(rest.length); // 2
136136
*/!*
137137
```
138138

139-
The value of `rest` is the array of the remaining array elements. We can use any other variable name in place of `rest`, just make sure it has three dots before it and goes last in the destructuring assignmemnt.
139+
The value of `rest` is the array of the remaining array elements. We can use any other variable name in place of `rest`, just make sure it has three dots before it and goes last in the destructuring assignment.
140140

141141
### Default values
142142

@@ -155,7 +155,7 @@ If we want a "default" value to replace the missing one, we can provide it using
155155
```js run
156156
*!*
157157
// default values
158-
let [name="Guest", surname="Anonymous"] = ["Julius"];
158+
let [name = "Guest", surname = "Anonymous"] = ["Julius"];
159159
*/!*
160160

161161
alert(name); // Julius (from array)
@@ -168,7 +168,7 @@ For instance, here we use the `prompt` function for two defaults. But it will ru
168168

169169
```js run
170170
// runs only prompt for surname
171-
let [name=prompt('name?'), surname=prompt('surname?')] = ["Julius"];
171+
let [name = prompt('name?'), surname = prompt('surname?')] = ["Julius"];
172172

173173
alert(name); // Julius (from array)
174174
alert(surname); // whatever prompt gets
@@ -248,7 +248,7 @@ let options = {
248248
};
249249

250250
*!*
251-
let {width=100, height=200, title} = options;
251+
let {width = 100, height = 200, title} = options;
252252
*/!*
253253

254254
alert(title); // Menu
@@ -266,7 +266,7 @@ let options = {
266266
};
267267

268268
*!*
269-
let {width=prompt("width?"), title=prompt("title?")} = options;
269+
let {width = prompt("width?"), title = prompt("title?")} = options;
270270
*/!*
271271

272272
alert(title); // Menu
@@ -281,7 +281,7 @@ let options = {
281281
};
282282

283283
*!*
284-
let {width:w=100, height:h=200, title} = options;
284+
let {width: w = 100, height: h = 200, title} = options;
285285
*/!*
286286

287287
alert(title); // Menu
@@ -434,7 +434,7 @@ let options = {
434434
function showMenu(*!*{title = "Untitled", width = 200, height = 100, items = []}*/!*) {
435435
// title, items – taken from options,
436436
// width, height – defaults used
437-
alert( title + ' ' + width + ' ' + height ); // My Menu 100 200
437+
alert( `${title} ${width} ${height}` ); // My Menu 200 100
438438
alert( items ); // Item1, Item2
439439
}
440440

@@ -452,12 +452,12 @@ let options = {
452452
*!*
453453
function showMenu({
454454
title = "Untitled",
455-
width:w = 100, // width goes to w
456-
height:h = 200, // height goes to h
455+
width: w = 100, // width goes to w
456+
height: h = 200, // height goes to h
457457
items: [item1, item2] // items first element goes to item1, second to item2
458458
}) {
459459
*/!*
460-
alert( title + ' ' + w + ' ' + h ); // My Menu 100 200
460+
alert( `${title} ${w} ${h}` ); // My Menu 100 200
461461
alert( item1 ); // Item1
462462
alert( item2 ); // Item2
463463
}
@@ -487,8 +487,8 @@ We can fix this by making `{}` the default value for the whole destructuring thi
487487

488488
```js run
489489
// simplified parameters a bit for clarity
490-
function showMenu(*!*{ title="Menu", width=100, height=200 } = {}*/!*) {
491-
alert( title + ' ' + width + ' ' + height );
490+
function showMenu(*!*{ title = "Menu", width = 100, height = 200 } = {}*/!*) {
491+
alert( `${title} ${width} ${height}` );
492492
}
493493

494494
showMenu(); // Menu 100 200

0 commit comments

Comments
 (0)