...

/

Solution Review: Shallow Copy

Solution Review: Shallow Copy

In this lesson, we will discuss the solutions to the questions in the previous lesson.

Question 1: Solution review #

In the previous lesson, you were given the following code:

Press + to interact
const girl = {
name: 'Anna',
info: { age: 20, number: 123 }
};
const newGirl = { ...girl };
newGirl.info.age = 30;
console.log(girl.info.age, newGirl.info.age);

For the code above, you had to answer the following question:

Explanation #

Run the code below to see the output:

Press + to interact
const girl = {
name: 'Anna',
info: { age: 20, number: 123 }
};
const newGirl = { ...girl };
newGirl.info.age = 30;
console.log(girl.info.age, newGirl.info.age);

As you can see, Option C is the correct answer. Let’s discuss why.

There is an object, ...

Access this course and 1400+ top-rated courses and projects.