Changes to object still reflected after object assign

I assign oldScore to newScore.

Later on when I update the newScore object, the changes are reflected to oldScore, can someone assist?

The changes made to newScore should not be reflected to oldScore. newScore and oldScore are two distinct and different objects.

words.newScore = Object.assign( {}, words.oldScore );

Thank you


Object.assign will shallow copy, means toplevel object’s own properties only. May you are trying to update nested object’s values, thus it’s updating old instance too. For that you need to Deep Copy instances.
For more details refer: MDN - Object.assign(): Warning for Deep Clone