-
Notifications
You must be signed in to change notification settings - Fork 0
/
day48.js
34 lines (28 loc) · 889 Bytes
/
day48.js
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
// Parameter destructuring
// Normal function which is Taking the Whole Object to Print the data of object
function printData(obj) {
console.log(`Name: ${obj.name}`);
console.log(`Age: ${obj.age}`);
console.log(`Hobbies: ${obj.hobbies}`);
obj.greet();
console.log(`Friends: ${obj.friends}`);
}
// Function to print the data of object by parameter destructuring
function printDataByParamsDestructuring({ name, age, hobbies, greet, friends }) {
console.log(`Name: ${name}`);
console.log(`Age: ${age}`);
console.log(`Hobbies: ${hobbies}`);
greet();
console.log(`Friends: ${friends}`);
}
// Object
const person = {
name: "Lokesh Singh",
age: 30,
hobbies: ["reading", "games", "coding"],
greet: () => {
console.log("Hello there");
},
friends : ["Aniket", "Diwakar", "ritik"]
}
printDataByParamsDestructuring(person)