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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy