Intro to Destructing

Yusuf Adeyemo | January 29, 2019 · 1 min reading

Destructuring is a convenient way of extracting multiple values from data stored in (possibly nested) objects and Arrays. It can be used in locations that receive data (such as the left-hand side of an assignment).

const person = {
  name: "Max",
  age: 29,
  greet() {
    console.log("Hi, I am " + this.name);
  }
};

const printName = ({ name }) => {
  console.log(name);
};

printName(person);

Array Example:

const hobbies = ["Sports", "Cooking"];
const [hobby1, hobby2] = hobbies;
console.log(hobby1, hobby2);

Written by

Yusuf Adeyemo

Award Winning Full Stack Developer with focus on Backend. I also like to develop BOT, you can see the ones I created in my portfolio.