In JavaScript, expressions are evaluated from left to right.
This means that your single line file is evaluated as follows:
a ^= b ^= a ^= b;
=> a = a ^ (b = b ^ (a = a ^ b))
=> a = 6 ^ (b = 4 ^ (a = 6 ^ 4))
=> a = 6 ^ (b = 4 ^ 2)
=> a = 6 ^ 6 = 0
b = 4 ^ 2 = 6
In C ++, you make unordered changes for the same object, so the program is undefined.
The moral of this is that smart code rarely happens.