Dear, probably this is trivial for you… Can you explain or link a good article explaining this counterintuitive behavior in object assignment (see below). Thanks
function changeKey ( newValue , obj ) {
obj [ ‘key’ ] = newValue ;
return obj ;
}
**const** obj1 = { 'key' : 'oldValue' };
console . log ( obj1 ); //key: 'oldValue'
**var** obj2 = {};
obj2 [ 'key' ] = obj1 [ 'key' ];
obj2 = changeKey ( 'newValue' , obj2 );
console . log ( obj2 ); //key: 'newValue'
console . log ( obj1 ); //key: 'oldValue'
**var** obj3 = obj1 ;
obj3 = changeKey ( 'newValue' , obj3 );
console . log ( obj3 ); //key: 'newValue'
console . log ( obj1 ); //key: 'newValue'
- minimal detail edited not affecting the issue