I am trying to swap two variables in JavaScript, but my code does not work. Can anyone tell me why?
This should return 10, 5 I think, because I already called the swap function. But instead, it returns 5, 10.
function swap(a, b) {
var temp = a;
a = b;
b = temp
}
var x = 5;
var y = 10;
swap(x, y);
console.log(x, y);