@akasaurabhverma

If you want it to work in expected fashion, you need to implement toString method in each of the object a and b; 
Like this:

const a = { key: 123, toString() { return this.key } };
  const b = { key: 456, toString() { return this.key } };
  const c = {};
  c[a] = 1;
  c[b] = 2;

  console.log(c[a]); // 1
  console.log(c[b]); // 2

@shakeelkhan625

inventor of javascript knows it all

@szulcus-n4z

Or just use TS and ESLint

@akshaylokray

But here we accessed a[b] which should be undefined?

@ytfeelslikenorthkorea

the most important question that should be asked is:
Why do you insist on bringing misery to this world? Why can't you learn some proper programming language?

@ET_AYY_LMAO

Because object gets turned into a string, [object object], but lets be frank, if you need to debug something like this, the codebase sucks and is jeeted to hell and back.

@kalpanagupta6166

Because JS only allows String or Symbol as key. Anything else if converted to string .

@MohiyuddinShaikh

And this is exactly why I have started to hate JS after 5+ years of working with it. A language shouldnt allow this in the first place. If not for TS, I'd have left this toy language for sure.

@davidgillies620

The result of this is your pull request fails code review and your PM asks you why you;re writing deliberately obfuscatory code.

@bcawallahvlogs7547

Because of Non-primitive datatype. It override in that original object..

@crashtagiyev

What is the point of const then? Just for reference assaignment?)

@IshanRohatgiyt

[Object, object]

@bigdreaminvestor

I have solved this question in one of the interview 😅

@HKJk-k2y

Javascript is really mfkr programming language

@BeeRich33

How can she slap?

@karthiksundaram544

undefined error

@abdulroufshaik123

❤️❤️

@alisher-iz1zq

interview