-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestructuring.js
56 lines (44 loc) · 1.12 KB
/
destructuring.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Array Destructuring
const numbers = [42, 65];
/* const x = numbers[0];
const y = numbers[1];
console.log(x, y); */
// const [x, y] = [42, 65];
const [x, y] = numbers;
function getValues(num1, num2) {
const nums = [num1, num2];
return nums;
}
// const [first, second] = [90, 34];
const [first, second] = getValues(90, 32);
// console.log(getValues(90, 32));
const student = {
name: 'jerin',
id: 38,
age: 23,
movies: ['x', 'y'],
}
const [firstMovie, secondMovie] = student.movies;
// Object destructuring
const { name, age } = { name: 'jerry', age: 23 };
const { names, ages } = { id: 12, names: 'jerry', ages: 23 };
const employee = {
id: 'VS Code',
designation: 'developer',
machine: 'mac',
language: ['html', 'css', 'javaScript'],
specification: {
height: 66,
weight: 67,
address: 'Sylhet',
Drink: 'Water',
watch: {
color: 'black',
price: 500,
brand: 'garmin',
}
}
}
const { machine, id } = employee;
const { weight, address } = employee?.specification;
const { brand } = employee?.specification?.watch;