const myEval = code => eval(code); function swap(a, b) { myEval(`a = ${b}; b = ${a}`); } let a = 0, b = 1; swap(a, b); console.log(a); console.log(b);