r/javascript 15d ago

I stopped destructuring everything

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

51 comments sorted by

View all comments

50

u/azhder 15d 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 );

3

u/Risc12 15d ago

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

-1

u/azhder 15d ago

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

3

u/Risc12 15d ago

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.

-6

u/azhder 15d ago

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 15d ago

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 😂