DEV Community

Andreas Riedmüller
Andreas Riedmüller

Posted on

2

Destructuring can worsen code readability

Destructuring objects is handy and often code is easier to read when it looks simpler.

But destructured variables lack context and this can worsen code readability.

Here is an example:

// A.)
const {title} = game;
// A FEW LINES LATER…
const text = title; // Title what?
Enter fullscreen mode Exit fullscreen mode
// B.) 
const text = game.title; // It's the title of the game!
Enter fullscreen mode Exit fullscreen mode

Use destructuring when the context is obvious and your code gets hard to read without.

This post is mostly a reminder to myself not to always deconstruct everything. Because I just had to trace a number of variables to understand where they came from.

Happy coding!

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay