Select Page

Code

Reflections on what I’ve learned in my coding adventure…

Destructuring Assignment
If we have this:
const myFavorites = {
     color: ‘blue’,
     car: ‘ferrari’,
     food: {
          breakfast: ‘eggs’,
          lunch: ‘sandwich’,
          dinner: ‘pizza’
     }
     band: ‘pearl jam’
}

To pull information from food would look like this:
const breakfast = myFavorites.food.breakfast;
const lunch = myFavorites.food.lunch;
const dinner = myFavorites.food.dinner;

That took three lines of code. Destructuring simplifies those three lines of code:
const {breakfast, lunch, dinner} = myFavorites.food