Destructuring

PHOTO EMBED

Sun Apr 28 2024 01:09:48 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #objects #destructuring

const todo = {
  id: 1,
  firstName: "David",
  lastName: "Mchale",
  age: 40,
  user: {
    isLoggedIn: false,
  },
};


// using curly braces means we are destructuring
// NOT using curly braces and using ':' means we are just renaming

const {
  id: position, // renaming
  firstName,
  lastName,
  age,
  user: { isLoggedIn }, // getting the value from the user isLoggedIn
} = todo;
console.log("destructure => ", firstName, lastName, age, isLoggedIn, position);
content_copyCOPY