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

141
Views
Passing by reference and value

Why is it that when i pass an object into the function for an argument, a reference is passed. But when i pass one of the keys in the object as an argument, it seems that a value is passed instead. I would have thought that the where 25 is stored in memory, the memory address would be passed?

Any ideas why?

let x = {name: 'Mike', age: 25};

function changeObject(x, y){
    x.name = 'Elena';
    y = 23;
    console.log(x);
};

changeObject(x, x.age);
console.log(x);

OUTPUT

{
name:"Elena",
age:25
}
{
name:"Elena",
age:25
}
about 4 years ago · Juan Pablo Isaza
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!