4 ms·
Objects are always treated as a reference, primitives as a value. To say they're immutable requires a bit more of a context - immutable in what sense? You can r
by Byamarro 5y ago
Objects are always treated as a reference, primitives as a value.
To say they're immutable requires a bit more of a context - immutable in what sense? You can reassign a different value to a variable that stores a primitive, so it's not like variables that store them are immutable.
I guess that the simpliest explanation would be by code:
let x = 4
let z = x
z = w
// x is still 4
let x = { b: 3 }
let z = x
z.b = 2
// x is { b: 2 }, because x and z hold reference to the same object