Data stored by value v/s stored by reference
This section is generally incorrect.
There is no difference between object values and other values regarding value/reference semantics or mutability.
Consider that the following example will result in b.name === 'a'. If b were a reference to a, then it would result in b.name === 'b'.
let a = { name: 'a' }; let b = a; a = { name: 'b' };
The key here is that only variables and properties are mutable.
So when you say b = a; you are copying the immutable value of a.
When you say a.name = 'd'; you are modifying a property associated with a, but you are not changing the value of a.
I keep seeing people making similar claims to this, so I'm curious where they're getting this misinformation -- could you let me know?
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.
This section is generally incorrect.
There is no difference between object values and other values regarding value/reference semantics or mutability.
Consider that the following example will result in b.name === 'a'.
If b were a reference to a, then it would result in b.name === 'b'.
The key here is that only variables and properties are mutable.
So when you say b = a; you are copying the immutable value of a.
When you say a.name = 'd'; you are modifying a property associated with a, but you are not changing the value of a.
I keep seeing people making similar claims to this, so I'm curious where they're getting this misinformation -- could you let me know?