repl.it : https://repl.it/BuXR/3
var str = "abc";
var str2 = str.split(" ").join("").split("");
var tmp = str2;
console.log(str2);
// => ['a','b','c']
console.log(tmp.reverse());
// => ['c','b','a']
console.log(str2);
// => ['c','b','a']
My question is why str2 is being changed even though it is not being reversed?
This is very upsetting to me, but I have a guess as to why this is happening. The tmp is just a pointer to the original str2, and when I call reverse() on tmp, it actually reverses str2.
Even if that really is what's happening, I still feel like it is a very counterintuitive way for a language to work.