You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**[:top: Scroll to Top](#javascript-output-based-interview-questions)**
903
910
911
+
**50. What will be the output**
912
+
```js
913
+
let a = {};
914
+
let b = { key:"abc" };
915
+
let c = { key:"efg" };
916
+
917
+
a[b] =111;
918
+
a[c] =222;
919
+
console.log(a[b]);
920
+
```
921
+
<details>
922
+
<summary><b>View Answer</b></summary>
923
+
<ul>
924
+
<li><b>Output</b> : 222</li>
925
+
<li><b>Reason</b> :In JavaScript, using an object as a key in a normal object turns it into a string. That string is usually "[object Object]". So, two different objects like b and c become the same key -> a[b] = 111 & a[c] = 222 becomes a["[object Object]"] = 111 & a["[object Object]"] = 222. Hence, the second value (222) replaces the first one. </li>
926
+
</ul>
927
+
</details>
928
+
929
+
**[:top: Scroll to Top](#javascript-output-based-interview-questions)**
0 commit comments