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

153
Views
Javascript Map Set object reference: is this a standard to the language?

I have tested this code

const map1 = new Map();
let foo = function() {
  this.test = 1;
}
let foo2 = new foo();
map1.set('bar', foo2);

foo2.test = 2;
console.log(map1.get('bar').test);
// prints 2, not 1

on the code snippet section of

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set

However this behavior is not specified anywhere in the same document and I couldn't find any other reference by googling.

Notice that in the Map.get document, it is stated clearly that

If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map object.

My question is, is the above Map.set behavior guaranteed to work in all implementations and all versions of javascript, or is the behavior not really standardized and can vary between versions.

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!