Hi there,
if I have the following object and I want to change the value of the property firstName.
let person = {
firstName: ‘Mosh’,
age: 30,
};
console.log(person);
person.firstName = ‘John’. This syntax is not working, only if I want to read the value using console.log(person.firstName). How can I change it from the object itself?
Not sure what you are doing wrong this worked just fine for me:
let person = {
firstName: 'Mosh',
age: 30,
};
console.log(person);
person.firstName = 'John';
console.log(person);
Printed out:
{ firstName: 'Mosh', age: 30 }
{ firstName: 'John', age: 30 }
My issue is that I was trying to log on the console only .firstName but as I can see here you log the whole person. Thank you!