let a = 10; let b = 20; let tmp; tmp = a; a = b; b = tmp;
const [x, y] = [1, 2];
Destructuring assignments are extremely useful in a handful of situations, including swapping two variables. To accomplish this, we can create an array from the two variables, then use a destructuring assignment to reassign them to each other:
let a = 10; let b = 20; [a , b] = [b, a];
A collection of quick tips and tricks to level up your coding skills one step at a time.
Creates an object from an array, using a function to map each value to a key.
Maps the values of an array to an object using a function.
Splits values into two groups, based on the result of the given filtering function.