If you assign an object or array to a variable, the variable doesn't store its complete value in that variable but the variable only stores its reference value, if you reassign that variable to any other value only that reference is copied to the new variable. since reference value in both variables are the same if you update any of the variables both will get updated. If you want to make a duplicate of an object you have to use spread operator(...) or Object.assign method, this will make a shallow copy of the object
// Using spread operator
const obj2 = {...obj1}
// Using Object.assign
const obj2 = Object.assign({}, obj1)