MediumEvent Loop & Promises💻 Output Question

Deep Copy and Shallow Copy in Asynchronous Operations

💡

Hint

Consider how modifying the original object affects the copies when dealing with nested objects

What does this output?

let originalObject = { a: 1, b: { c: 2 } }
let shallowCopy = { ...originalObject }
let deepCopy = JSON.parse(JSON.stringify(originalObject))
originalObject.b.c = 3
console.log(shallowCopy.b.c)
console.log(deepCopy.b.c)

Correct Output

3
2

Why this output?

More Event Loop & Promises Output Questions

EasySynchronous code runs before setTimeoutMediumPromise microtask before setTimeout macrotaskMediumPromise chain passes valuesHardTwo Promise chains interleave in microtask queue

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz