Variable re-assignment of object reference leaves other object unaltered (no “transitive” assignment)

Not possible. JS passes objects by a copy of the reference, so in the step var ref = obj1 you’re not actually assigning a reference pointer like you would in a language like C. Instead you’re creating a copy of a reference that points to an object that looks like {x: 'a'}.

See this answer for other options you have: https://stackoverflow.com/a/17382443/6415214.

Leave a Comment