...

/

Solution Review: Destructuring

Solution Review: Destructuring

Take a look at the solution to the destructuring challenge given in the previous lesson.

Solution

Let’s start by reviewing the solution code step-by-step.

Press + to interact
'use strict';
'use strict';
const getDetails = function({name, born: { year: birthYear }, graduated: {year}}) {
return `${name} born in the year ${birthYear}, graduated in ${year}.`;
};
const details =
getDetails({name: 'Sara',
born: { month: 1, day: 1, year: 2000 },
graduated: { month: 5, day: 31, year: 2018 }});
console.log(details);
//Sara born in the year 2000, graduated in 2018.

Explanation

The object passed as a parameter to the getDetails() function is a nested object. The output displays the three values given in that nested object.

  1. name
  2. born
...