DEV Community

Tim Pozza
Tim Pozza

Posted on

Array and Object Destructuring in Context

Doing discovery for a project, I used a few DEV resources to reorient. There's a lot of great stuff here by a lot of very talented people.

By cobbling the code below, it was my hope to better understand the subtleties of destructuring, and to decide for myself which is best implemented between array and object. The code is maybe overly commented, but it does include a few links to sources right here on DEV.

It shouldn't come as a surprise to anyone who uses destructuring in their code that for complex and spread out projects, objects offer the best and most internalized clarity; key names become variable names, and it just doesn't get better than that.

Arrays, on the other hand, must be commented separately. This comes with a greater risk of separation. If you lose the comment which spells out names for each value of your array, the array won't help you by spelling out a revealing name, values which might be in use and which you have to find on the receiving end to make sense of what you're looking at.

If you're a beginner, teasing apart this file might help you learn something about destructuring, a generator pattern, and function currying. It might also help you choose between an array and an object for passing setup parameters, as it did for me in making it.

Thanks to all the folks at DEV for making a sometimes difficult subject easier, digestible, and always interesting.

Top comments (0)