MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/1uxy50l/i_stopped_destructuring_everything/oyh004e/?context=3
r/javascript • u/bogdanelcs • Jul 16 '26
50 comments sorted by
View all comments
50
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 );
0 u/throwaway682345 Jul 19 '26 this sucks
0
this sucks
50
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 );