Day 30: Destructuring Assignment in JavaScript
#WomenWhoCode
#100DaysOfCode

šŸ§µ
Destructuring assignment is a special syntax introduced in ES6, for neatly assigning values taken directly from an object.
1āƒ£ to Extract Values from Objects:
šŸ“Œthe name and age variables will be created and assigned the values of their respective values from the user object.
šŸ“ŒYou can see how much cleaner this is.
šŸ“Œ You can extract as many or few values from the object as you want.
2āƒ£ to Assign Variables from Objects:
Destructuring allows you to assign a new variable name when extracting values. You can do this by putting the new name after a colon when assigning the value.
3āƒ£ to Assign Variables from Nested Objects:
4āƒ£ to Assign Variables from Arrays:
One key difference between the spread operator and array destructuring is that the spread operator unpacks all contents of an array into a comma-separated list. you cannot pick or choose which elements you want to assign to variables.
5āƒ£ with the Rest Parameter to Reassign Array Elements:
šŸ“ŒSometimes, we might want to collect the rest of the elements into a separate array.
šŸ“ŒIs similar to Array.prototype.slice()
šŸ“ŒThe rest element only works correctly as the last variable in the list.
6āƒ£ to Pass an Object as a Function's Parameters:
šŸ“Œyou can destructure the object in a function argument itself.
The end of this thread. šŸ˜

Thank you for your time, I hope you found it useful. ā¤ļø
You can follow @habibawael02.
Tip: mention @twtextapp on a Twitter thread with the keyword ā€œunrollā€ to get a link to it.

Latest Threads Unrolled: