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
let sampleArr = [1, 2, 3, 4, 5]; | |
let [x, y] = sampleArr; | |
[y, x] = [x, y]; | |
let subArr; | |
[x, y, ...subArr] = sampleArr; | |
console.log(subArr); //[3, 4, 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
var sampleArr = [1, 2, 3, 4, 5]; | |
var x = sampleArr[0], | |
y = sampleArr[1]; | |
var temp = [x, y]; | |
y = temp[0]; | |
x = temp[1]; | |
var subArr; | |
x = sampleArr[0]; | |
y = sampleArr[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
function addThreeNumbers(a, b, c) { | |
return a + b + c; | |
} | |
let sampleArr = [1, 2, 3]; | |
console.log(addThreeNumbers(...sampleArr)); //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 sampleArr = [1, 9, 17, -3, 7, 89, 40, 100, 121, 8]; | |
const maxValue = Math.max(...sampleArr); | |
const minValue = Math.min(...sampleArr); | |
console.log(maxValue); //121 | |
console.log(minValue); //-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
let [x,y,z] = 'a\uD83D\uDCA9c'; // x='a'; y='\uD83D\uDCA9'; z='c' | |
let [p, q] = new Set(['new', 'string']); // p='new'; q='string’; |
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
let sampleObj = { | |
firstName: 'John', | |
lastName: 'Doe', | |
age: 29, | |
gender: 'male' | |
}; | |
let { name, firstName, lastName, gender:sex } = sampleObj; | |
//name = undefined, firstName = John, lastName = Doe, sex = male |
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
var sampleObj = { | |
firstName: John, | |
lastName: Doe, | |
age: 29, | |
gender: male | |
}; | |
var name = sampleObj.name, //undefined | |
firstName = sampleObj.firstName, //John | |
lastName = sampleObj.lastName, //Doe |
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 printName({firstName, lastName}) { | |
console.log(`Name : ${firstName} ${lastName}`); | |
}; | |
let personObj = { | |
firstName: 'John', | |
lastName: 'Doe' | |
}; | |
printName(personObj); //Name : John Doe |
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
let obj1 = { | |
a: 1, | |
b: 2, | |
c: 3 | |
}; | |
let obj2 = { | |
p: 4, | |
q: 5, | |
r: 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
switch(valueStore) { | |
case A: { | |
function 1(); | |
break; | |
} | |
case B: { | |
function2(); | |
break; | |
} | |
default: { |
OlderNewer