+ 1

What's the point of this lesson? JavaScript Course

I'm now learning ES6 and I just finished learning how to destructure arrays and now I learn about object destructuring, however, in the lesson the second and third examples seem just pointless and stupid to me, this one for example: let {a,b} = {a: 'Hello', b:' Jack'} ; document.write( a+b ); Why would I ever do this, if I could simple do: let [a,b] = ['Hello', ' Jack']; document.write( a+b ); I understood the part which talks about how to define the object properties into variables, it's the other examples like the one I wrote above that seem unnecessary. Here is the course link: https://www.sololearn.com/learn/JavaScript/2977/

27th Oct 2020, 3:36 PM
Karak10
Karak10 - avatar
1 Réponse
+ 2
In realistic case you would most probably destructure an object returned by some function. Since it would be too long to introduce the function, you are given a short example, just to see what can be done and how.
27th Oct 2020, 4:16 PM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar