--

Hello Alejandro and thanks for response.

As I describe in the article and try to summarize here:

- It's more DRY.

- It is declarative.

- It avoids JS to dig into deep data structures multiple times.

- It is safer, with the habit of including defaults. They also go well together with default parameters in function headers, which is a nice and common syntax that work the same way as destructuring defaults.

- It can keep the scope cleaner, free from variables that you don't need.

- You can utilize the powerful rest operator (both for objects & arrays).

Consider that you in some function need:

`profile.user.address.street.number` & `profile.user.address.city`

Without destructuring you'd have to type:

`profile?.user?.address?.street?.number ?? ""` & `profile?.user?.address?.city ?? ""`

With destructuring, made as early as possible in a suitable way for the situation, you know that you have safe short values to work with:

`streetNumber` & `city`

--

--

Esbjörn Blomquist
Esbjörn Blomquist

Written by Esbjörn Blomquist

Software architect and developer with web and functional JavaScript close to his heart. Worked many years with web solutions mainly within the IoT field.

Responses (1)