Advertisement
728x90
The destructuring assignment is a JavaScript expression that makes it possible to unpack values from arrays or properties from objects into distinct variables.
Let's get the month values from an array using destructuring assignment
javascript
1var [one, two, three] = ["JAN", "FEB", "MARCH"];
2
3console.log(one); // "JAN"
4
5console.log(two); // "FEB"
6
7console.log(three); // "MARCH"and you can get user properties of an object using destructuring assignment,
javascript
1var { name, age } = { name: "John", age: 32 };
2
3console.log(name); // John
4
5console.log(age); // 32Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 58
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
315of476