Destructuring on object lets you bind different properties of an object at any depth.

Accessing the object property

Doing a deep or nested destructuring

Wait, what?

If I destructedauthor, why is it not defined?

How to write cleaner code with JavaScript

What is going on is actually really simple.

So hey always remember that.

Then we can access that variable in our code.

Article image

Its important to notice that a variable with the original propertynamein our case name wont be defined.

In this case, the variable is created with valueundefined.

The default values are only assigned when the property isundefined.

Article image

But there are some nice tricks too.

This may be subtle but it has big consequences in the end results.

If we want dynamic keys (as those stored on a variable) we need to use computed properties.

Article image

Heres an example:

Pretty awesome right!

Destructuring function arguments

Destructing variables can be placed anywhere where we can declare variables.

For example by usinglet,constorvar, but its also possible to deconstruct in function arguments.

Article image

It can really help your code be more readable.

it’s possible for you to follow Juan on Twitterhere.

Sign up for updates on everything related to programming, AI, and computer science in general.

Article image

Also tagged with

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image