Use Destructuring Assignment to Assign Variables from Nested Objects - in layman's terms

Use Destructuring Assignment to Assign Variables from Nested Objects - in layman's terms
0

#1

I am just barely understanding what is happening here. Can someone read my notes below and tell me if I have this right?

The following code:

const { start : { x: startX, y: startY }} = a;

will do the following steps:

1 - Find the constant called “a”.
2 - Within “a”, find the key called “start”.
3 - In “start”, look for another key called, “x” and get it’s value.
4 - Use that value and assign it to a new variable called “startX”


#2

Yes, you seem to have the general concept. The only clarifications I would make are that:

Variable a does not have to be a const. You are defining a new constant named startX.

Instead of keys, you are referencing the object a’s properties.