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?
// B.)
const text = game.title; // It's the title of the game!
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)