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 sampleValues = [1, 4, 5, 2, 'a', 'e', 'b', 'e', 2, 2, 4]; | |
const uniqueValues = [...new Set(sampleValues)]; | |
console.log(uniqueValues); //[1, 4, 5, 2, "a", "e", "b"] |
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 unique = (value, index, self) => { | |
return self.indexOf(value) === index; | |
} | |
const sampleValues = [1, 4, 5, 2, 'a', 'e', 'b', 'e', 2, 2, 4]; | |
const uniqueValues = sampleValues.filter(unique); |
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 switchObject2 = Object.assign(Object.create(null), { | |
A : function1, | |
B : function2, | |
default: defaultFunction, | |
}); | |
/* OR | |
var switchObject2 = Object.create(null); | |
switchObject2['A'] = function1; |
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 switchObject1 = { | |
A : function1, | |
B : function2, | |
default: defaultFunction, | |
} | |
var resultFunction = switchObject1[valueStore] || switchObject1['default']; | |
resultFunction(); |
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: { |
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
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
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
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
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’; |
NewerOlder