However this behavior changes when it comes to non-primitive types (objects, arrays, etc) as const.
Actually, it doesn't change at all.
const x = y;
This means that you may not reassign x, and this is true regardless of y having a primitive of object value.
The confusion is due to conflating the properties of an object with the value of the object.
The value of the object is the object's identity, and this allows you to access the properties associated with that object.
These properties can be modified, but modifying the properties does not change the value (or identity) of the object.
non-primitive types (objects, arrays, etc) as const.
When you use const, it has nothing to do with the value -- const only affects the variable.
Thanks for correcting my mistake, I really appreciate it! 👍
You're welcome. :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Actually, it doesn't change at all.
This means that you may not reassign x, and this is true regardless of y having a primitive of object value.
The confusion is due to conflating the properties of an object with the value of the object.
The value of the object is the object's identity, and this allows you to access the properties associated with that object.
These properties can be modified, but modifying the properties does not change the value (or identity) of the object.
When you use const, it has nothing to do with the value -- const only affects the variable.
Thanks for correcting my mistake, I really appreciate it! 👍
You're welcome. :)