The actual function I provided in this example is not the problem. I just want to know how to save the values of variables after using them as parameters in functions. I was trying to make a very simple function that switches the value of two variables. I know how to do this without a function but wanted to generalize the solution with a function.
I tried writing the following code,
let a = 3;
let b = 4;
const switchItems = (c,d) => {
var temp = c;
c = d;
d = temp;
}
switchItems(a,b);
I expected a to be 4 and b to be 3 but the variables stay the same as they were before the function.
I don't care how to do this with the specific swap function I used, I just want to know how to change a global variable inside a function without referencing it.