Guess the JavaScript Output: Very Tricky!
Sadeedpv🥇

Sadeedpv🥇 @sadeedpv

About: Human being

Location:
Kerala, India
Joined:
Feb 19, 2022

Guess the JavaScript Output: Very Tricky!

Publish Date: Oct 5 '23
12 6

This post is part of a series called Guess the JavaScript Output
And today's question is a bit tricky one:

What will be the output of the following code?

let a = {};
let b = { key: "b" };
let c = { key: "c" };

a[b] = 123;
a[c] = 456;

console.log(a[b]);
Enter fullscreen mode Exit fullscreen mode

Uncle Mike solved this within 20s (Mike started coding in the womb and has built his own OS called MikeOS).
If you'd like to see more of the series, please give it a like.

Comments 6 total

  • Bob dnaeil
    Bob dnaeilOct 5, 2023

    123

  • Jon Randy 🎖️
    Jon Randy 🎖️Oct 5, 2023

    456

    • Jon Randy 🎖️
      Jon Randy 🎖️Oct 5, 2023

      I won't write why as it makes it too easy for everyone else :)

  • Akash Bais
    Akash BaisOct 5, 2023

    456

  • blackr1234
    blackr1234Oct 6, 2023

    Guess the object should be casted to something. The values of b and c should result in the same value. So would guess 456 as the element gets overwritten. a[c] should give 456 too.

  • RahulBenzeen
    RahulBenzeenOct 10, 2023

    456

Add comment