Skip to content

Commit 3d71b3a

Browse files
authored
Create Destructuring.md
1 parent 1527836 commit 3d71b3a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Destructuring.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Destructuing in JavaScript
2+
3+
```javascript
4+
// 1
5+
const apiObject = {
6+
data: {
7+
user: 'Alex',
8+
twitterHandle: 'alexpaul'
9+
},
10+
status: 200,
11+
}
12+
13+
// 2
14+
const { data } = apiObject;
15+
16+
// 3
17+
console.log(data);
18+
// { user: 'Alex', twitterHandle: 'alexpaul' }
19+
20+
/*
21+
1. An object with various key, value pairs
22+
2. Using destructing to get to only the values we need from an object.
23+
3. Prints out only the { data } key,value pair
24+
*/
25+
26+
/*
27+
Use destructuring to retrieve status, add to step 2 above as we can use comma delimeter to include more properties for destructuring
28+
*/
29+
```

0 commit comments

Comments
 (0)