Swapping variables is simple enough, but can it be any simpler?
Consider the below code -
|
|
To swap values -
|
|
Applying our earlier knowledge about destructuring objects(/destructuring-assignments-in-javascript/), we can instead do -
|
|
Beautiful, isn’t it?