Destructuring




The ability to destructure properties of an object or array helps us write more expressive code with less errors.
const obj = {
  firstName: "Jean",
  surnameName: "Snyman",
  age: 32,
  role: "Solutions Architect"
};

const { firstName } = obj;
console.log(firstName); // jean

Destructure an array.

const arr = [10, 20, 30, 40, 50];
[a, b] = arr;

console.log(a);