-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson_7.js
More file actions
42 lines (34 loc) · 958 Bytes
/
lesson_7.js
File metadata and controls
42 lines (34 loc) · 958 Bytes
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
// Destructuring
// Assign variables from objects
// Normal Way
var voxel = {x:3.6, y:7.4, z: 6.54 };
// var x = voxel.x; // x = 3.6
// var x = voxel.y; // x = 7.4
// var x = voxel.z; // x = 6.54
//with Destructuring
const {x, y,} = voxel;
console.log(x);
const {x : a, y : b, z : c} = voxel;
console.log(b);
// Assign variables from nested objects
const nest= {
start: {x: 5, y: 6},
end: {x: 6, y: -9}
};
const { start: { x: startX, y: startY}} = nest;
console.log(startX);
// Assign Variables from Arrays
const [q,,, r] = [1, 2, 3, 4, 5];
console.log(q, r);
// Rest Operator to Reassign Array Elements
const [t, u, ...rest] = [1, 2, 3, 4, 5];
console.log(t, u);
console.log(rest)
// Pass an Object asa Functions's Parameters
//const profileUpdate = ({ name, age, nationality, location}) => {
// do something with these variables
//}
// Destructuring
const profileUpdate = ({ name, age }) => {
// do something with these variables
}