-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathes6_7_destructuring.js
More file actions
46 lines (35 loc) · 926 Bytes
/
Copy pathes6_7_destructuring.js
File metadata and controls
46 lines (35 loc) · 926 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
43
44
45
46
/**
* ES6/ES2015
* Destructuring
* @author Mahmud Ahsan
* {@link https://github.com/mahmudahsan/javascript}
*/
/**
* Destructuring is an easier way to access properties in objects and arrays
*/
const person = {
name: "Mahmud",
country: "Bangladesh",
};
// individual variable
// const { name } = person;
// console.log(name);
// be careful to use actual property name
// here if i use nameAgain it will not work
// const { nameAgain, country } = person;
// console.log(nameAgain, " " + country);
// fix
const { name, country } = person;
console.log(name, " " + country);
// in function call common destructuring scenario
const personName = ( {name} ) => {
console.log(name.toUpperCase());
};
personName(person);
/**
* destructuring array
* In this case use [] square brackets instead of {}
*/
const arrNumbers = [1, 2, 3, 4, 5];
const [ one, two, three ] = arrNumbers;
console.log(one, two, three);