Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

67
Views
Why is my saved variable changing indirectly?
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

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!