The output of the variable is very strange.

topic description

the output of the object is not the expected result

sources of topics and their own ideas

in daily programming

related codes

        var obj = {"a" : 1};
        var obj1 = {"b" : obj};
        console.log(obj1);
        console.log(obj);
        obj.a = 3;

what result do you expect? What is the error message actually seen?

expected result: {b: {aburel}}. The actual output is shown in figure

.
Jul.23,2021

if you output like this, the result will be as expected:

var obj = {"a" : 1};
var obj1 = {"b" : obj};
console.log(JSON.stringify(obj1));
console.log(JSON.stringify(obj));
obj.a = 3;

this is because methods such as console.log/dir/. display the latest state of the object in memory when it is output, so the value of a in your output has been modified to the latest value (that is, affected by obj.a = 3 ).

Menu