-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Description
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?