Software engineer with a deep knowledge on web technologies and the JavaScript ecosystem. Currently spending most of my time developing web apps with React, Node and Typescript.
You're reading some documentation for Mozilla, not Javascript.
Mutable is a type of variable that can be changed. In JavaScript, only objects and arrays are mutable, not primitive values.
This is obviously wrong, since objects and arrays are not variables.
Next you need to understand what mutability for objects and arrays means.
let a = { name: 'a' };
let b = { name: 'b' };
let c = a;
// This changes a property of a, but does not change the value of a.
// c === a remains true.
a.name = 'c';
// This changes the value of a, but does not change the properties of that value.
// c === a becomes false
a = b;
What this means is that the value of the object is immutable, but properties of an object may be mutable.
If you read the ecmacscript standard, you'll find exactly zero mention of 'heap' -- because this is an implementation detail, not part of the language.
Software engineer with a deep knowledge on web technologies and the JavaScript ecosystem. Currently spending most of my time developing web apps with React, Node and Typescript.
All I wrote is supported by the docs.
Mutability:
developer.mozilla.org/en-US/docs/G...
Memory:
developer.mozilla.org/en-US/docs/W...
developer.mozilla.org/en-US/docs/W...
And I quote:
You're reading some documentation for Mozilla, not Javascript.
This is obviously wrong, since objects and arrays are not variables.
Next you need to understand what mutability for objects and arrays means.
What this means is that the value of the object is immutable, but properties of an object may be mutable.
If you read the ecmacscript standard, you'll find exactly zero mention of 'heap' -- because this is an implementation detail, not part of the language.
ecma-international.org/publication...
I don't think that example is correct.
Just give it a try.
After
a.name = 'c'
,c === a
is still true.Changes are applied to both variables, because they are just a reference.
On the other hand, I agree about ecmascript. But Mozilla is just a common implementation.
And btw, thank you for taking your time to contribute to the discussion. I find really interesting to know different points of view.
a.name = 'c'; does not change any variable.
That's why the variables are still the same.
There are no references involved.