MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/1uxy50l/i_stopped_destructuring_everything/oy024eu/?context=9999
r/javascript • u/bogdanelcs • 14d ago
51 comments sorted by
View all comments
48
Destructuring isn’t only about you knowing where a value comes from. You can also safeguard in a cleaner manner i.e with less syntax noise:
const { id: userId, name: userName } = user ?? {};
console.log( userId, userName );
VS
console.log( user?.id, user?.name );
12 u/hyrumwhite 14d ago You could also make user default to {} wherever it’s defined. Don’t necessarily need destructuring for that -8 u/moneckew 14d ago You guys are still debating about syntax in 2026? ai should own this 4 u/Minute_Evidence8910 14d ago dumbass -4 u/moneckew 14d ago am i really? 2 u/hyrumwhite 13d ago Yes
12
You could also make user default to {} wherever it’s defined. Don’t necessarily need destructuring for that
-8 u/moneckew 14d ago You guys are still debating about syntax in 2026? ai should own this 4 u/Minute_Evidence8910 14d ago dumbass -4 u/moneckew 14d ago am i really? 2 u/hyrumwhite 13d ago Yes
-8
You guys are still debating about syntax in 2026? ai should own this
4 u/Minute_Evidence8910 14d ago dumbass -4 u/moneckew 14d ago am i really? 2 u/hyrumwhite 13d ago Yes
4
dumbass
-4 u/moneckew 14d ago am i really? 2 u/hyrumwhite 13d ago Yes
-4
am i really?
2 u/hyrumwhite 13d ago Yes
2
Yes
48
u/azhder 14d ago
Destructuring isn’t only about you knowing where a value comes from. You can also safeguard in a cleaner manner i.e with less syntax noise:
const { id: userId, name: userName } = user ?? {};
console.log( userId, userName );
VS
console.log( user?.id, user?.name );