Imed Adel Posted on Apr 12, 2020 [a, b] = [b, a] #todayilearned #javascript 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} Top comments (0) Subscribe Submit Preview Dismiss Code of Conduct • Report abuse
Top comments (0)