Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMax van den Berge
6,506 Pointsusing variable const in an Object Literal.
In early courses, i thought i learned that using const variable, you couldn't change the value of that variable. and that i you want to change a value inside a variable its better to use let (or var)
but this code does run, how does it relate to that explanation about choosing the type of variable?
const person = { name: 'Edward', };
person.name= rachel
;
person.city = 'New York';
let message = hi my name is ${person.name}. I live in ${person.city}
;
document.write(message);
love to hear for you ! gr. Max
2 Answers
Steven Parker
231,271 PointsSince it was declared const, you cannot reassign "person". It will always refer to that object.
However, you can still add, remove, or alter the properties of the object. The properties are not constants.
Max van den Berge
6,506 PointsMakes sense, thanks!