0

how can I exchange the value of 2 variables without using a third one, in Javascript, thanks

28th Jul 2020, 8:02 AM
bubbleCode
bubbleCode - avatar
3 Answers
+ 5
In ES6, you can use array destructuring. Example let a = 1 let b = 2 [a, b] = [b, a] console.log(a - b) //outputs 1 (2 - 1)
28th Jul 2020, 8:09 AM
XXX
XXX - avatar
+ 1
It is quit simple var a = 10; var b = 20; [a,b]=[b,a] console.log(a,b); See this
28th Jul 2020, 8:10 AM
Ayush Kumar
Ayush Kumar - avatar
0
thanks, for me the best solution is destructuring array
28th Jul 2020, 8:13 AM
bubbleCode
bubbleCode - avatar