Lately, I've been encountering an issue with assigning values to a sub-object in JavaScript. Here is my sample code:
var user = {
name: {
fname: 'Apple'
}
};
console.log(user);
user.name.fname = 'Orange';
console.log(user);
Even though the console shows the output twice, the value of fname always displays as Orange. However, I want the output to be Apple and then Orange. How can I achieve this, or what is actually happening here? Please explain what is going on.