Skip to main content
InterviewHubPRO
Section Overview
Q319

Question 319 of 536

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

60%
JavaScript & V8 Internals (536 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

What is destructuring assignment

junior LevelCode ExamplejavascriptES6+ Modern Syntax

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
  var [one, two, three] = ["JAN", "FEB", "MARCH"];

  console.log(one); // "JAN"
  console.log(two); // "FEB"
  console.log(three); // "MARCH"

and you can get user properties of an object using destructuring assignment,

javascript
  var { name, age } = { name: "John", age: 32 };

  console.log(name); // John
  console.log(age); // 32