JS Coding Questions Logo
JS Coding Questions
#315💼 Interview💻 Code

What is destructuring assignment

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); // 32

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 58

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
315of476