r/javascript • u/bogdanelcs • Jul 16 '26
I stopped destructuring everything
https://allthingssmitty.com/2026/07/13/i-stopped-destructuring-everything/
84
Upvotes
r/javascript • u/bogdanelcs • Jul 16 '26
View all comments
Show parent comment
-7
u/azhder Jul 16 '26
No, that’s syntax noise, but one I often use as I employ more sophisticated defaults, not ??.
Usually one object as an argument is all you need, props or options or whatever you name it. I will simply use $
const users = asArray($?.users);
Now, you could imagine the asArray has a check Array.isArray(), not just ??, but it can be even more complex than that. You can even do
const {pass: users, fail: error} = asUsers($?.users);
And just like that, destructuring pops up again - less messy than
usersResult.value
usersResult.error
But even this last one is something I regularly use. It all on a case by case basis.