|
2 | 2 |
|
3 | 3 | The two most used data structures in JavaScript are `Object` and `Array`. |
4 | 4 |
|
5 | | -- Objects allow us to create a single entity that stores data items by key. |
| 5 | +- Objects allow us to create a single entity that stores data items by key. |
6 | 6 | - Arrays allow us to gather data items into an ordered list. |
7 | 7 |
|
8 | 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. |
9 | 9 |
|
10 | | -*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. |
| 10 | +*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. |
11 | 11 |
|
12 | 12 | Destructuring also works great with complex functions that have a lot of parameters, default values, and so on. Soon we'll see that. |
13 | 13 |
|
@@ -76,7 +76,7 @@ In the code above, the second element of the array is skipped, the third one is |
76 | 76 | let [a, b, c] = "abc"; // ["a", "b", "c"] |
77 | 77 | let [one, two, three] = new Set([1, 2, 3]); |
78 | 78 | ``` |
79 | | -That works, because internally a destructuring assignment works by iterating over the right value. It's kind of syntax sugar for calling `for..of` over the value to the right of `=` and assigning the values. |
| 79 | +That works, because internally a destructuring assignment works by iterating over the right value. It's a kind of syntax sugar for calling `for..of` over the value to the right of `=` and assigning the values. |
80 | 80 | ```` |
81 | 81 |
|
82 | 82 |
|
@@ -176,7 +176,7 @@ alert(rest.length); // 2 |
176 | 176 | */!* |
177 | 177 | ``` |
178 | 178 |
|
179 | | -The value of `rest` is the array of the remaining array elements. |
| 179 | +The value of `rest` is the array of the remaining array elements. |
180 | 180 |
|
181 | 181 | 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. |
182 | 182 |
|
@@ -254,7 +254,7 @@ alert(width); // 100 |
254 | 254 | alert(height); // 200 |
255 | 255 | ``` |
256 | 256 |
|
257 | | -Properties `options.title`, `options.width` and `options.height` are assigned to the corresponding variables. |
| 257 | +Properties `options.title`, `options.width` and `options.height` are assigned to the corresponding variables. |
258 | 258 |
|
259 | 259 | The order does not matter. This works too: |
260 | 260 |
|
@@ -429,7 +429,7 @@ let options = { |
429 | 429 | height: 200 |
430 | 430 | }, |
431 | 431 | items: ["Cake", "Donut"], |
432 | | - extra: true |
| 432 | + extra: true |
433 | 433 | }; |
434 | 434 |
|
435 | 435 | // destructuring assignment split in multiple lines for clarity |
|
0 commit comments