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/09-destructuring-assignment/article.md
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@ let user = {
99
99
100
100
// loop over keys-and-values
101
101
*!*
102
-
for(let [key, value] of Object.entries(user)) {
102
+
for(let [key, value] of Object.entries(user)) {
103
103
*/!*
104
104
alert(`${key}:${value}`); // name:John, then age:30
105
105
}
@@ -113,7 +113,7 @@ user.set("name", "John");
113
113
user.set("age", "30");
114
114
115
115
*!*
116
-
for(let [key, value] of user.entries()) {
116
+
for(let [key, value] of user.entries()) {
117
117
*/!*
118
118
alert(`${key}:${value}`); // name:John, then age:30
119
119
}
@@ -136,7 +136,7 @@ alert(rest.length); // 2
136
136
*/!*
137
137
```
138
138
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.
140
140
141
141
### Default values
142
142
@@ -155,7 +155,7 @@ If we want a "default" value to replace the missing one, we can provide it using
155
155
```js run
156
156
*!*
157
157
// default values
158
-
let [name="Guest", surname="Anonymous"] = ["Julius"];
158
+
let [name="Guest", surname="Anonymous"] = ["Julius"];
159
159
*/!*
160
160
161
161
alert(name); // Julius (from array)
@@ -168,7 +168,7 @@ For instance, here we use the `prompt` function for two defaults. But it will ru
168
168
169
169
```js run
170
170
// runs only prompt for surname
171
-
let [name=prompt('name?'), surname=prompt('surname?')] = ["Julius"];
171
+
let [name=prompt('name?'), surname=prompt('surname?')] = ["Julius"];
172
172
173
173
alert(name); // Julius (from array)
174
174
alert(surname); // whatever prompt gets
@@ -248,7 +248,7 @@ let options = {
248
248
};
249
249
250
250
*!*
251
-
let {width=100, height=200, title} = options;
251
+
let {width=100, height=200, title} = options;
252
252
*/!*
253
253
254
254
alert(title); // Menu
@@ -266,7 +266,7 @@ let options = {
266
266
};
267
267
268
268
*!*
269
-
let {width=prompt("width?"), title=prompt("title?")} = options;
269
+
let {width=prompt("width?"), title=prompt("title?")} = options;
270
270
*/!*
271
271
272
272
alert(title); // Menu
@@ -281,7 +281,7 @@ let options = {
281
281
};
282
282
283
283
*!*
284
-
let {width:w=100, height:h=200, title} = options;
284
+
let {width: w =100, height: h =200, title} = options;
0 commit comments