This file contains 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 first = 200 && 300 && 100; | |
const second = 0 && 300 && 200; | |
const third = first || second && 0; | |
// What's the output? | |
console.log(first + second + third); |
This file contains 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 url = 'https://www.myportfolio.com/experience/resume.pdf'; | |
const result = (function(url) { | |
return url.split('/').pop(); | |
}(url)); | |
// What's the output? | |
console.log(result); |
This file contains 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 prices = { beer: 8, water: 1, latte: 4, | |
soda: 2, coffee: 3, wine: 12, }; | |
function filter(prices) { | |
return Object.keys(prices).reduce((acc, key) => { | |
if (prices[key] % 2 === 0) { | |
delete acc[key]; | |
} | |
return acc; | |
}, prices); |
This file contains 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 curve = 5; | |
const students = [ | |
{ name: 'Thor', score: 98 }, | |
{ name: 'Wonder Woman', score: 92 }, | |
{ name: 'Spiderman', score: 98 }, | |
{ name: 'Captain America', score: 88 }, | |
]; | |
const scores = [...new Set(students.map(x => x.score + curve))]; |
This file contains 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
// What's the output? | |
console.log(NaN == NaN); | |
console.log(NaN === NaN); | |
console.log(Number.isNaN(NaN)); |
This file contains 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 ids = []; | |
const data = ['139', '576']; | |
data.map(id => ids.push(Math.max(...id))); | |
// What's the output? | |
console.log(ids); |
This file contains 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 dog1 = { | |
name: 'Scout', | |
age: 7, | |
}; | |
const dog2 = { | |
name: 'Snoopy', | |
age: 3, | |
}; |
This file contains 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
/* Optional Chaining (?.) in ES2020 */ | |
const app = { | |
frontend: { | |
language: 'JavaScript', | |
framework: 'ReactJS', | |
}, | |
backend: { | |
language: 'Python', | |
}, | |
database: { |
This file contains 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
// What is the output? | |
const object = {}; | |
console.log(!!Object.keys(object).length); |
This file contains 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
/* Promise.all() => Wait for multiple promises to resolve then proceed */ | |
const promise1 = new Promise((resolve, reject) => { | |
setTimeout(resolve, 1000, 'Resolving 1'); | |
}); | |
const promise2 = new Promise((resolve, reject) => { | |
setTimeout(resolve, 2000, 'Resolving 2'); | |
}); | |
const promise3 = new Promise((resolve, reject) => { | |
setTimeout(resolve, 1000, 'Resolving 3'); | |
}); |