What is the output of the following? “`js const map = new Map(); const key = {}; map.set(key, ‘value’); console.log(map.get({})); console.log(map.get(key)); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js const map = new Map(); const key = {}; map.set(key, ‘value’); console.log(map.get({})); console.log(map.get(key)); “`

Key points

  • Objects are compared by reference in JavaScript.
  • When a new object is created, it is not the same as the original object.
  • The `key` object used to set the value must be the same object used to retrieve the value.

Ready to go further?

Related questions