DEV Community

Discussion on: What Javascript Spread Operator is, How It Works and How to Use It

 
jdforsythe profile image
Jeremy Forsythe

You're moving the goal posts. I said it distinguishes between an object and primitives. That is demonstrated by the example in my first comment, which is why it's not a deep copy. Every interpreter runs my example the same way, allowing you to mutate the original using the copy.

Every interpreter since I started writing JS in the 1990s treats objects and primitives differently. There are countless articles over the last 20 years about that fact. You can't really believe that everyone is wrong. Given that, it must be you who misunderstands the spec. So I suggest you look up all the definitions of things used inside GetValue. If you look at it long enough, you'll see that it quite clearly follows a different path for primitive values than it does for objects.

Thread Thread
 
pentacular profile image
pentacular

What's the distinction that it makes?

JS doesn't allow you to mutate values at all -- and there's no difference between objects and values in that regard.

The only things you can mutate in JS are properties and variables.

(And this is one of the reasons that properties are not part of the object's value)

Thread Thread
 
fernandomk6 profile image
Fernando Henrique

Objects and primitives have their values copied when the assignment sign is used. Primitive values are literal values, object values are pointers.