forked from MadhavBahl/dailyjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.js
36 lines (31 loc) · 1010 Bytes
/
1.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
35
36
/**
* Destructuring
* Pulling properties out of objects
* make a greetings function which takes
* studentDetails object as argument and returns a greeting message
*/
var studentDetails = {
first_name: "Madhav",
last_name: "Bahl",
profession: "Student",
age: 21
};
// Without Destructuring
function greetings1 (studentDetails) {
var first_name = studentDetails.first_name;
var last_name = studentDetails.last_name;
var profession = studentDetails.profession;
var age = studentDetails.age;
return `Hi, I am ${first_name} ${last_name}.
I am a ${profession}
My age is ${age}`
}
console.log ("Without destructuring: ", greetings1(studentDetails));
// With Destructuring
function greetings2 (studentDetails) {
var { first_name, last_name, profession, age } = studentDetails;
return `Hi, I am ${first_name} ${last_name}.
I am a ${profession}
My age is ${age}`
}
console.log ("Without destructuring: ", greetings2(studentDetails));