

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Objects
incomplete
2: No Colon
incomplete
3: Updating Properties
incomplete
4: Nesting Properties
incomplete
5: Nesting Properties Quiz
incomplete
6: Optional Chaining
incomplete
7: When to Chain
incomplete
8: Object Methods
incomplete
9: Methods Mutate
incomplete
10: Initializing Props
incomplete
11: Strings As Keys
incomplete
12: This
incomplete
13: Arrow Functions
incomplete
14: Fat Arrows and This
incomplete
15: Spread Syntax
incomplete
16: Return Objects
incomplete
17: Destructuring
incomplete
18: Not Bound
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
It's admittedly annoying to have to get the return values from an object by using the . operator. The destructuring assignment lets us unpack object properties easily.
So, instead of this:
const apple = {
radius: 2,
color: "red",
};
const radius = apple.radius;
const color = apple.color;
We can do this:
const apple = {
radius: 2,
color: "red",
};
const { radius, color } = apple;
I use it all the time to unpack function return values:
function getApple() {
const apple = {
radius: 2,
color: "red",
};
return apple;
}
const { radius, color } = getApple();
console.log(radius); // 2
console.log(color); // red
Destructuring also works in function parameters, which means that if you write a function that takes an object as an argument, you can unpack the object's properties in function definition.
So, instead of this:
function eatApple(apple) {
console.log(`ate a ${apple.color} apple with a radius of ${apple.radius}`);
}
We can do this:
function eatApple({ radius, color }) {
console.log(`ate a ${color} apple with a radius of ${radius}`);
}
Now that you've fixed the output of calculateCampaignMetrics, use destructuring to assign openRate, clickRate and conversionRate from the given call on line 14.