You're exactly right. It is a referencing situation. There is no cloning going on when you assign an object to a variable, the program just creates a new reference to person1 called person2
You would have to use a dedicated cloning function, depending on if you are using pure JS or a framework like jQuery.
Here is a pure JS solution (source http://heyjavascript.com/4-creative-ways-to-clone-objects/):
function cloneObject(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
var temp = obj.constructor(); // give temp the original obj's constructor
for (var key in obj) {
temp[key] = cloneObject(obj[key]);
}
return temp;
}
var person2 = cloneObject(person1);