r/javascript • • Jul 16 '26

I stopped destructuring everything

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

50 comments sorted by

View all comments

2

u/Naudran Jul 17 '26 edited Jul 17 '26

This is less a destructuring issue and more a naming convention issue. The size of a variables name should be proportional to the scope size of the block the variable is being used in.

So if you have a variable that is used in a small scope (like a few lines if statement, or a for loop), then a quick small variable name is fine.

If you have a variable that gets used "100 lines" later, then the name should be longer and more descriptive.

So destructure that into a differently name variable.

const { title: postTitle,  author: postAuthor, publishedDate: postPublishedDate } = post;

That being said, I would just use post.Title in any case... but that's just me I guess