-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (38 loc) · 1.17 KB
/
Copy pathscript.js
File metadata and controls
45 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Normal Way
const sandwich = {
title: "Wendy's",
price: 7,
description: "Scully's favourite",
ingredients: ["bread", "cheddar cheese", "corned beef", "dressing", "mayonese", "mustard sauce", "more cheese"]
}
console.log("Name:", sandwich.title)
console.log("Price: $", sandwich.price)
// Using destructuring
const {
title,
description,
price
} = {
title: "Pizza Hut",
price: 7,
description: "No one outpizza's the hut",
ingredients: ["cheese burst", "cheddar cheese", "corned beef", "dressing", "soft base", "more cheese"]
}
console.log("------------------")
console.log("Name:", title)
console.log("Description: ", description)
console.log("Price $: ", price)
console.log("------------------")
const vacation = {
destination: "Chile",
activity: "Sky Diving",
cost: "Can't afford even if I told."
}
function marketing({
destination,
activity
}) {
return `Come to ${destination} and do some ${activity}.`
}
// We pass in vacation object to the marketing function, marketing function parses the variables or the keys that we are interested in and then returns their values as template strings.
console.log(marketing(vacation))