I noticed this behavior when writing my JavaScript, and I could not understand why:
Below is the code to reproduce the behavior in question.
var o1 = {
num: 1
}
var o2 = o1;
o2.num = 2;
alert (o1.num);
Expected Result: Browser Warning 1, because I only changed the property of the o2 object , not the o1 object .
Actual result: The browser warns 2, because it seems that o1 is equal to o2 .
I'm not sure what is going on. How can I fix the code so that it warns 1 and 2 (assuming that o1 has not changed)?
Thank you very much in advance.