re: Practical Ways to Write Better JavaScript VIEW POST

FULL DISCUSSION
 

Maybe I'm a dinosaur, but I don't always find arrow functions nor destructuring to be more readable/understandable.

This:

function animalParty(dogSound, catSound) {}

const myDict = {
  dog: 'woof',
  cat: 'meow',
};

animalParty(myDict.dog, myDict.cat);

Is easily the more readable solution vs:

function animalParty(dogSound, catSound) {}

const myDict = {
  dog: 'woof',
  cat: 'meow',
};

const { dog, cat } = myDict;
animalParty(dog, cat);

With the former, you can also get more info about the variable just from how it's used.

dog allows you to access the value of the myDict property, yes. But myDict.dog not only allows a developer to access the value, but it also allows for the dev to know immediately that the variable is a property of an object, which can give a clue on where to look to get more insight into the larger object itself.

code of conduct - report abuse