-
Notifications
You must be signed in to change notification settings - Fork 69
/
destructuring.html
106 lines (90 loc) · 2.46 KB
/
destructuring.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Destructuring</title>
</head>
<body>
<script>
{
const names = ["Eko", "Kurniawan", "Khannedy", "Budi", "Joko"];
let [firstName, middleName, lastName, ...others] = names;
console.info(firstName);
console.info(middleName);
console.info(lastName);
console.info(others);
}
{
const person = {
firstName: "Eko",
lastName: "Khannedy",
address: {
street: "Jalan Belum Ada",
city: "Jakarta",
country: "Indonesia"
},
hobby: "Game",
channel: "Programmer Zaman Now"
};
let {firstName, lastName, address: {city, street, country}, ...others} = person;
console.info(firstName);
console.info(lastName);
console.info(city);
console.info(street);
console.info(country);
console.info(others);
}
{
function displayPerson({firstName, middleName, lastName}) {
console.info(firstName);
console.info(middleName);
console.info(lastName);
}
const person = {
firstName: "Eko",
middleName: "Kurniawan",
lastName: "Khannedy",
};
displayPerson(person);
}
{
function sum([first, second]) {
return first + second;
}
console.info(sum([1, 1]));
console.info(sum([10, 10]));
}
{
const names = ["Eko", "Budi", "Joko"];
const [firstName, middleName = "Kurniawan", lastName = "Khannedy"] = names;
console.info(firstName);
console.info(middleName);
console.info(lastName);
}
{
const person = {
firstName: "Eko",
middleName: "Budi",
lastName: "Khannedy"
};
let {firstName, middleName = "Kurniawan", lastName} = person;
console.info(firstName);
console.info(middleName);
console.info(lastName);
}
{
const person = {
firstName: "Eko",
middleName: "Budi",
lastName: "Khannedy"
};
let {firstName: namaDepan,
middleName: namaTengah = "Kurniawan",
lastName: namaBelakang} = person;
console.info(namaDepan);
console.info(namaTengah);
console.info(namaBelakang);
}
</script>
</body>
</html>