Skip to content

Commit 63d7d7d

Browse files
authored
Aliases with JavaScript Destructuring
1 parent 444412a commit 63d7d7d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,24 @@ const countMyFruits = myFruits.reduce((countFruits,fruit) => {
251251
console.log(fruitsCounter)
252252
// { Apple:3, Banana:1, Mango:2, Orange:1 }
253253
```
254+
255+
256+
# Aliases with JavaScript Destructuring
257+
258+
259+
```javascript
260+
261+
//There are cases where you want the destructured variable to have a different name than the property name
262+
263+
const obj = {
264+
name: "JSsnippets"
265+
};
266+
267+
268+
// Grabs obj.name as { pageName }
269+
const { name: pageName } = obj;
270+
271+
//log our alias
272+
console.log(pageName) // JSsnippets
273+
```
274+

0 commit comments

Comments
 (0)