Coding task · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

Practice: Object and Array Destructuring

Practice destructuring objects, arrays, nested structures, and function parameters

Task

You have an object const dino = { name: 'Rex', species: 'T-Rex', stats: { weight: 8000, speed: 30 } } and an array const zones = ['A', 'B', 'C', 'D']. Using object destructuring, create the variables dinoName (an alias for name), species, weight (from the nested stats) and diet with the default value 'carnivore'. Using array destructuring, create firstZone, secondZone and otherZones with the remaining elements. Also write a function describeDino({ name, species }) that destructures its parameter and returns the text name + ' (' + species + ')'.