The syntax in the last line is confusing to me because first we’ve to destruct the object a using {} brackets to access its value. Then we’ve to access the value of the properties inside start, which itself is an object, to get the values of x and y. Here we don’t use the same syntax like, {x: startX, y:startY} = a.start. Is it always like this for nested objects or am I missing something?
if you have multiple objects nested, in this way you still need only one line instead of one line for each nested object, so you use nested destructuring
inside destructuring you use : to say “put the value of what’s to the left of it, in what is to the right of it”
so when you do {start : ...} you are taking the value of the property start and putting it to the right of it. that’s already the value of the property start, so you don’t need any extra syntax to do destructuring with that value
I’m not quite sure your thinking as to what the inconsistentcy is here. You are accessing a.start.x and a.start.y.
However, I get that it is confusing to read. Ideally, destructuring nested objects it not something you want to be doing very often because it can get very hard to read very fast.
Ah, in-place destruction. That’s where I missed it. Otherwise, the syntax didn’t make sense because putting the value of what’s to the left of : which is an object itself, in what’s to the right which is also the same.