This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const a = [1, 2, 3, 4]; | |
| const [x, y, z] = a; | |
| console.log(x, y, z) // 1 2 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const user = {name: 'thanos', stones: {time: {color: 'green', achieved: true, from: 'Dr. Strange'} } } | |
| const {stones: {time}} = user; | |
| const {stones: {time: {achieved: isTimeStoneAchieved, color: timeStoneColor}}} = user; | |
| console.log(time); // {color: "green", achieved: true, from: "Dr. Strange"} | |
| console.log(isTimeStoneAchieved, timeStoneColor); // true "green" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const user = {id: 1, username: 'thanos', email: 'thanos@infinity.gauntlet'}; | |
| const {id: userId, username, email: userEmail} = user; | |
| console.log(userId, username, userEmail) // 1 "thanos" "thanos@infinity.gauntlet" | |
| console.log(id) // ReferenceError: id is not defined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const obj = {a: 1, b:2, c:3}; | |
| const {a, b} = obj; | |
| console.log(a, b) // 1 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const param = [Math.PI / 2]; | |
| console.log(Math.sin(...param)) // 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const a = { | |
| l: { | |
| m: 1 | |
| } | |
| } | |
| const b = {...a} | |
| b.l.m = 5; | |
| console.log(a.l.m); // 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const a = { | |
| x: 1, | |
| y: 1 | |
| } | |
| const b = { | |
| ...a, | |
| z: 1 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const arr1 = [1, 2]; | |
| const arr2 = [3, 4]; | |
| const arr3 = [5, 6]; | |
| const arr2 = [...arr1, ...arr2, ...arr3]; | |
| console.log(arr2) // [1, 2, 3, 4, 5, 6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const arr1 = [3, 4]; | |
| const arr2 = [1, 2, ...arr1, 5, 6]; | |
| console.log(arr2) // [1, 2, 3, 4, 5, 6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add(...args){ | |
| let sum = 0; | |
| for(let value of args){ | |
| sum += value; | |
| } | |
| return sum; | |
| } |