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

126
Views
Someone please explain this javascript code to me

This is the code

looks like the global user var is affected by function body

var user =  { name: 'Ivan' };

function setUser(user) {
    console.log("asdf", user);
    // user = { name: "asdf", a: 1 }
    user.name = 'Oleg';
    console.log("qwer", user)
}

setUser(user);

commented adding user = { name: "asdf", a: 1 } changes result

function setUser(user) {
    console.log("asdf", user);
    user = { name: "asdf", a: 1 }
    user.name = 'Oleg';
    console.log("qwer", user)
}

setUser(user);

console.log("1234", user, user.name);

this is the result ( chrome console )

Result

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!