DEV Community

Discussion on: The vanilla Javascript basics to know before learning React JS

Collapse
 
sqlrob profile image
Robert Myers

const can neither be re-assigned nor updated, it is constant(doesn’t change).

I think that is a little misleading. The reference is constant, the object is not; fields can be reassigned and added.

const x = { y: 'x is const' };
x.y = 'y is not';
x.a = 'here is a new property';
console.log(x.y); // y is not
console.log(x.a); // here is a new property
delete x.y;
console.log(x.y);  // undefined
Enter fullscreen mode Exit fullscreen mode

Colloquially, those are all updates.

Collapse
 
tracycss profile image
Jane Tracy πŸ‘©πŸ½β€πŸ’»

You can not reassign an object or an array but you can still change the values or properties.
Let me change the text a little.
Thanks for pointing this out Robert, yeahhhh :)