Created
January 7, 2017 10:27
-
-
Save jurosh/1351508229deb061e81bb959a837b257 to your computer and use it in GitHub Desktop.
Swap 2 values in JavaScript (hacky way)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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