Today I realized that I can easily swap values in JavaScript using destructuring 😲 I don't know how I never noticed this before!
let a = 1, b = 2
[a, b] = [b, a]
console.log({a, b}) //=> {a: 2, b: 1}
Today I realized that I can easily swap values in JavaScript using destructuring 😲 I don't know how I never noticed this before!
let a = 1, b = 2
[a, b] = [b, a]
console.log({a, b}) //=> {a: 2, b: 1}
For further actions, you may consider blocking this person and/or reporting abuse
Leapcell -
Cláudio Filipe Lima Rapôso -
Méschac Irung -
keploy -
Top comments (0)