Destructuring assignment in JavaScript

Mohammad Yasir
Feb 17, 2021

Destructuring assignment in JavaScript is used to unpack(retrieve) the value from Array or Object with easy way.

Now Look at a code , where we unpack value from Array and Object without using Destructuring assignment.

Now, See how we can achieve the same thing using destructuring.

No if we compare the both methods, We find that using destructuring makes its easy & simple.

For ex. we can see that there are repetition of codes in first method (we have to type many times ‘arr’ and ‘obj’), But in case of destructuring, there are no repetition.

Some advance feature in object destructuring:

Now let supose , you want to use varaibles with some other name:

Please note here if we use x,y,z , it will not work & it will throw the error (Uncaught ReferenceError)

--

--