Why is my saved variable changing indirectly?

Viewed 23
var data = {
             "glob": "test1my-account:membership:homepage",
             "val": {
                     "func": "attr",
                     "name": "variables/prop5"
                    },
             "description": "Page Name",
             "func": "matches"
           }
var replace_dimen_def = {
      old : "test", 
      new : "new",
    }

  function find_replace(dimen){
        if (dimen.func == 'matches') {
            var re_old = new RegExp(replace_dimen_def.old); 
            dimen.glob = dimen.glob.replace(re_old,replace_dimen_def.new);
            return dimen;
         } 
  }

  function update_segment(def_contain){
      var dimen = def_contain;
      const old_dimen = def_contain;          
      const replace_dimen = find_replace(dimen);
      console.log(old_dimen);
  }

update_segment(data);

why is const old_dimen changing? I don't want it to change. The const old_dimen should keep the original data. It seems like I'm re-assigning a value being def_contain but not sure how

0 Answers
Related