Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:43:08+00:00 2026-06-11T04:43:08+00:00

What is going on in this code? var a = {a:1}; var b =

  • 0

What is going on in this code?

var a = {a:1};
var b = {b:2};
var c = {};

c[a] = 1;
c[b] === 1 // true!

c[b] = 2;
c[a] === 2 // true!

Specifically, why does using looking up b in c return the value that was stored in a property of a?

What does it mean to use an object as a key to a property in JavaScript?

I’ve tested this in Chrome/Node and in Firefox.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:43:09+00:00Added an answer on June 11, 2026 at 4:43 am

    What does it mean to use an object as a key to a property in JavaScript?

    Javascript objects only allow string keys, so your object will first be coerced to a string.

    Specifically, why does using looking up b in c return the value that was stored in a property of a?

    The string representation of {a: 1} and {b: 2} are both "[object Object]", thus, the property is overwritten.

    Edit: If you really need to use objects as keys (I would prefer another solution, if possible), you could use the object’s JSON representation:

    c[JSON.stringify(a)] = 1
    c[JSON.stringify(b)] = 2
    

    But, again, try to think of a different approach. Perhaps the objects have unique identifiers other than the object itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Something very wrong is going on this piece of code: function getCookie(c_name) { var
Can anybody help with this code I just don't know where I am going
i am going through the code for xml parser, and i found this code,
I want to convert vb this code <?php // Where the file is going
am going to read 5- Contacts , So i get this code and go
I am going through a tutorial on XNA, and it uses this code: private
I think I'm going insane with this. I have a a piece of code
I need to create a WPF grid dynamically from code behind. This is going
So I'm going through old code (2.0) and I came across this: object isReviewingValue
To make this more clear, I'm going to put code samples: $file = fopen('filename.ext',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.