DEV Community

Discussion on: Destructuring JavaScript objects like a pro

Collapse
 
agronick profile image
Kyle Agronick

Thats cool. I didn't know you could do that with the default values. It seems backwards to me though with the variable to assign from on the left of the colon and the variable to assign to on the right.

Collapse
 
c24w profile image
Chris Watson

I found that slightly counterintuitive to start with, too, when you're used to name = value. The easiest way I find to remember the order is { from: to } = obj. Also, it wouldn't make much sense to use { to: from } = obj because you're no longer putting the from in the same position as the key is in the object.