Skip to content

Instantly share code, notes, and snippets.

@fupslot
Created February 8, 2016 13:08
Show Gist options
  • Save fupslot/909010b30d19b942aa03 to your computer and use it in GitHub Desktop.
Save fupslot/909010b30d19b942aa03 to your computer and use it in GitHub Desktop.
swap variable values (not temporary variable)
// variables
var a = 10;
var b = 99;
// a^=b, b^=a, a^=b - swap variables using XOR operation,
// details: http://en.wikipedia.org/wiki/XOR_swap_algorithm
a^=b, b^=a, a^=b;
console.log('a', a);
console.log('b', b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment