Skip to content

Commit 0c9b67f

Browse files
authored
Fixed alignment issue
1 parent 9b41c9f commit 0c9b67f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ const printName = () => {
458458

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

461-
**1. What will be the output (shallow copy of an object)**
461+
**28. What will be the output (shallow copy of an object)**
462462
```js
463463
const userDetails = {
464464
firstName: "Surbhi",
@@ -471,21 +471,20 @@ const userDetails = {
471471
};
472472

473473
let cloneUserDetails = { ...userDetails };
474-
475474
//Updating original object
476475
userDetails.age = 22;
477476
userDetails.address.city = "Banglore";
478477

479-
console.log(cloneUserDetails.age); // what will be the output
480-
console.log(cloneUserDetails.address.city); // what will be the output
478+
console.log(cloneUserDetails.age);
479+
console.log(cloneUserDetails.address.city);
481480
```
482481
<details>
483482
<summary><b>View Answer</b></summary>
484483
<ul>
485484
<li><b>Output</b> : 20, "Banglore"</li>
486-
<li><b>Explanation </b> : cloneUserDetails is created by using the spread syntax ({ ...userDetails }). This syntax creates a shallow copy of the userDetails object, meaning that the top-level properties are copied, but nested objects are still referenced.</li>
487-
<li><b>case 1</b> : Although userDetails.age was changed to 22, cloneUserDetails still holds the original value of 20. This is because the spread syntax only creates a shallow copy, so the age property of cloneUserDetails remains unchanged.</li>
488-
<li><b>case 2</b> : The nested address object is still referenced by cloneUserDetails, so when the city property of userDetails.address is changed, it reflects in cloneUserDetails.address as well. Therefore, the output is "Banglore".</li>
485+
<li><b>Reason </b> : cloneUserDetails is created by using the spread syntax ({ ...userDetails }). This syntax creates a shallow copy of the userDetails object, meaning that the top-level properties are copied, but nested objects are still referenced.</li>
486+
<li><b>case 1</b> : Although userDetails.age was changed to 22, cloneUserDetails still holds the original value of 20. This is because the spread syntax only creates a shallow copy, so the age property of cloneUserDetails remains unchanged.</li>
487+
<li><b>case 2</b> : The nested address object is still referenced by cloneUserDetails, so when the city property of userDetails.address is changed, it reflects in cloneUserDetails.address as well. Therefore, the output is "Banglore".</li>
489488
</ul>
490489

491490
</ul>

0 commit comments

Comments
 (0)