Skip to content

Instantly share code, notes, and snippets.

@jurosh
Created January 7, 2017 10:27
Show Gist options
  • Select an option

  • Save jurosh/1351508229deb061e81bb959a837b257 to your computer and use it in GitHub Desktop.

Select an option

Save jurosh/1351508229deb061e81bb959a837b257 to your computer and use it in GitHub Desktop.
Swap 2 values in JavaScript (hacky way)
// http://stackoverflow.com/questions/16201656/how-to-swap-two-variables-in-javascript
a = b + (b = a, 0)
// (b=a, 0) sets b to the old value of a and yields 0
// a = b + 0 sets a to the old value of b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment