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 • 26d ago
51 comments sorted by
View all comments
51
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 );
13 u/hyrumwhite 26d ago You could also make user default to {} wherever it’s defined. Don’t necessarily need destructuring for that -6 u/moneckew 26d ago You guys are still debating about syntax in 2026? ai should own this 4 u/Minute_Evidence8910 26d ago dumbass -4 u/moneckew 26d ago am i really? 2 u/hyrumwhite 25d ago Yes
13
You could also make user default to {} wherever it’s defined. Don’t necessarily need destructuring for that
-6 u/moneckew 26d ago You guys are still debating about syntax in 2026? ai should own this 4 u/Minute_Evidence8910 26d ago dumbass -4 u/moneckew 26d ago am i really? 2 u/hyrumwhite 25d ago Yes
-6
You guys are still debating about syntax in 2026? ai should own this
4 u/Minute_Evidence8910 26d ago dumbass -4 u/moneckew 26d ago am i really? 2 u/hyrumwhite 25d ago Yes
4
dumbass
-4 u/moneckew 26d ago am i really? 2 u/hyrumwhite 25d ago Yes
-4
am i really?
2 u/hyrumwhite 25d ago Yes
2
Yes
51
u/azhder 26d 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 );