Skip to content

Commit 0c81389

Browse files
authored
Added Question 50
1 parent c3393e5 commit 0c81389

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,10 @@ console.log(person.name);
742742
```js
743743
let a={ x:1, y: {alpha:10,beta:20} };
744744
let b = {...a};
745+
745746
b.x=101;
746747
b.y.alpha=1001;
748+
747749
console.log(a.x);
748750
console.log(a.y.alpha);
749751
```
@@ -761,12 +763,15 @@ console.log(a.y.alpha);
761763
**43. What will be the output**
762764
```js
763765
console.log('Start');
766+
764767
setTimeout(() => {
765768
console.log('setTimeout');
766769
}, 0);
770+
767771
Promise.resolve().then(() => {
768772
console.log('Promise');
769773
});
774+
770775
console.log('End');
771776
```
772777
<details>
@@ -800,6 +805,7 @@ console.log(array.length);
800805
let x = ["a","b","c"];
801806
let y = ["a","b","c"];
802807
let z = y;
808+
803809
console.log(x == y);
804810
console.log(z == y);
805811
console.log(z == x);
@@ -888,6 +894,7 @@ setTimeout(user.logMessage, 1000);
888894
```js
889895
const obj1 = { a: 1, b: 2 };
890896
const obj2 = { b: 3, c: 4 };
897+
891898
const finalObj = Object.assign({}, obj1, obj2);
892899
console.log(finalObj);
893900
```
@@ -901,3 +908,23 @@ console.log(finalObj);
901908

902909
**[:top: Scroll to Top](#javascript-output-based-interview-questions)**
903910

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)**
930+

0 commit comments

Comments
 (0)