Skip to content

Update the reason for preferring object destructuring? #2293

@michaelaflores

Description

@michaelaflores

The explanation for the preference for destructuring says:

Destructuring saves you from creating temporary references for those properties.

I've found that devs used to not destructuring find it such a big change that this explanation doesn't seem like a good reason, especially if there's an established habit of referencing object properties inline and not creating temporary references anyways. i.e. rather than:

// bad
function getFullName(user) {
  const firstName = user.firstName;
  const lastName = user.lastName;

  return `${firstName} ${lastName}`;
}

They are writing

// better?
function getFullName(user) {
  return `${user.firstName} ${user.lastName}`;
}

While I personally find this verbose and repetitive even in this small example, a developer coming from never using destructuring finds it to be far more straightforward and are thus resistant to this rule.

I say all this to ask, are there any additional reasons Airbnb prefers destructuring, and should those be included in the explanation for the rule?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions