Skip to content

Instantly share code, notes, and snippets.

@koistya
Created February 11, 2012 13:54
Show Gist options
  • Save koistya/1799515 to your computer and use it in GitHub Desktop.
Save koistya/1799515 to your computer and use it in GitHub Desktop.
Swap two values in JavaScript without using a temp variable
var _swap = function(a, b) {
return "".concat(a, " = [", b, ", ", b, " = ", a, "][0]")
};
var a = 1, b = 2;
eval(_swap('a', 'b'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment