One-Liners in JavaScript
JavaScript can do a lot of things. Here is a list of one-liners you should know to become a JavaScript pro. 1. Swap variables
1 2 3 4 5 |
let a = 10; let b = 20; [a, b] = [b,a]; console.log(a,b); // 20 10 |
2. Unique Elements Javascript has its own implementation of Hashmap known as Set.
1 2 3 4 |
const arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]; const uniqueValuesArr = (arr) => [...new Set(arr)]; console.log(uniqueValuesArr(arr)); // [1,2,3,4] |
3. Detect Dark Mode Now a days it is common to add…