DEV Community

Object Destructuring in ES6

Sarah Chima on October 31, 2017

This is a follow up article to my previous article on Array Destructuring. Except you have an idea of destructuring, you should read it. First, l...
Collapse
 
sammyisa profile image
Sammy Israwi

Great article! Picked up some tricks that I wish I knew before...

I always found confusing or misleading the syntax for assigning new variable names in object destructuring. Using : inside an object takes my mind to property assignment from right to left, not new variable assignment from left to right. Also, it is too similar to Typescript's type declaration:

const num: int = 5;

And fairly different (and less verbose than) using new variable names in import object destructuring:

import { Component as Comp} from "React";

Collapse
 
sarah_chima profile image
Sarah Chima

I'm glad you picked up some tricks Sammy. Thank you for reading.

Collapse
 
tobias_grasse profile image
Tobias Grasse

Thanks for this post! I learned some new tricks; your explanations of the pitfalls with object literal destructuring assignment with previous variable declaration were especially insightful :-)

Collapse
 
sarah_chima profile image
Sarah Chima

I'm glad you learnt some new tricks. Thanks for reading.

Collapse
 
sudheer160540 profile image
sudheer160540

Nice article sarah chima. I am learning a lot of things in this article.

Thanks for spending time for writing this article

Collapse
 
sarah_chima profile image
Sarah Chima

I'm glad you like it. 😊

Collapse
 
techtheriac profile image
Franklin Jezreel

This was quite useful. Thank you for watering down the vagueness of the concept.

Collapse
 
kmylo profile image
kmylo • Edited

Rest in Object Destructuring: [ERROR]

var person = {name: "Sarah", country: "Nigeria", job: "Developer" friends: ["Annie", "Becky"]};
Something missing comma between, "Developer" and friends.
Nice article, thx!

Collapse
 
iamtheiam profile image
IAMtheIAM

Thanks for the detailed and accurate explanation of object destructuring!

Collapse
 
ankurrai2602 profile image
Ankur

Thanks for writing a great article which covers a lot of details.

Collapse
 
a1ubkh4n profile image
Md.Aiub Khan

Thank you..Sarah

Collapse
 
rekh profile image
Rekh

Huh, got stuck on Javascript courses about Destructuring, but your post is really clear and will surely help me to defeat the evil forces of those exercices.

Thanks !

Collapse
 
sarah_chima profile image
Sarah Chima

I'm glad you found my post helpful

Collapse
 
spyrosko profile image
spyrosko

This was the most excellent article on object destructuring I've ever read. So thorough and easy to understand.

Collapse
 
sarah_chima profile image
Sarah Chima

Thanks a lot for reading.

Collapse
 
pedrodeveloper profile image
Pedro Toribio

This is the best article

Collapse
 
dottiboi profile image
NwanneMadu

Omo, finally it's clear. Thanks, nwanne.

Collapse
 
tcee42 profile image
Thomas

Thank you. Concise explanation just like you did in the array destructuring.