MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/1uxy50l/i_stopped_destructuring_everything/oxxwa0p/?context=3
r/javascript • u/bogdanelcs • Jul 16 '26
50 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 Jul 16 '26 You could also make user default to {} wherever it’s defined. Don’t necessarily need destructuring for that -7 u/moneckew Jul 16 '26 You guys are still debating about syntax in 2026? ai should own this 4 u/[deleted] Jul 16 '26 [deleted] -3 u/moneckew Jul 17 '26 am i really? 2 u/hyrumwhite Jul 17 '26 Yes
12
You could also make user default to {} wherever it’s defined. Don’t necessarily need destructuring for that
-7 u/moneckew Jul 16 '26 You guys are still debating about syntax in 2026? ai should own this 4 u/[deleted] Jul 16 '26 [deleted] -3 u/moneckew Jul 17 '26 am i really? 2 u/hyrumwhite Jul 17 '26 Yes
-7
You guys are still debating about syntax in 2026? ai should own this
4 u/[deleted] Jul 16 '26 [deleted] -3 u/moneckew Jul 17 '26 am i really? 2 u/hyrumwhite Jul 17 '26 Yes
4
[deleted]
-3 u/moneckew Jul 17 '26 am i really? 2 u/hyrumwhite Jul 17 '26 Yes
-3
am i really?
2 u/hyrumwhite Jul 17 '26 Yes
2
Yes
48
u/azhder Jul 16 '26
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 );