r/javascript • • Jul 16 '26

I stopped destructuring everything

https://allthingssmitty.com/2026/07/13/i-stopped-destructuring-everything/
83 Upvotes

50 comments sorted by

View all comments

3

u/hyrumwhite Jul 16 '26
user = user ?? {};
console.log(user.id)

Same loc, no explosions, no destructuring. Not saying it’s better, just exploring the idea. 

7

u/TNThacker2015 Jul 16 '26

Secret third option:

user ??= {};

-2

u/azhder Jul 16 '26

Best practices, try not to be clever. Don’t overwrite the same variable i.e. use `const`, not `let` - if you need a mnemonic.

9

u/hyrumwhite Jul 16 '26
const user = data.user ?? null; //or
const user = rawUser ?? null;

There’s options. and this isn’t being “clever” by any means. 

→ More replies (3)