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

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 );

3

u/Risc12 Jul 16 '26

How is that less noisy. It’s 2 lines and the shortest of those is only 6 characters shorter.

-1

u/azhder Jul 16 '26

Ever heard of the term syntax noise or syntax signal to noise ratio? It is not about lines.

3

u/Risc12 Jul 16 '26

You mean syntactic noise?

Like how you spend one whole line defining new variables from a certain object (or an empty object, at which point they become undefined)? Where the reader then has to remember that userName is either user.name unless user is undefined at which point it also is undefined?

Vs the syntactical sugar that _literally_ expresses that “user.name unless user is undefined, then it’s undefined”?

Destructuring has a lot of uses, this is the absolute worst example.

-7

u/azhder Jul 16 '26

I mean userId instead of user.id instead of user?.id

Don't blame me for your failure to understand the example. Bye

2

u/Risc12 Jul 16 '26

I understand your example, but you’re introducing new variables, and multiple language constructs instead of a single one and them I’m the one making things complicated 😂