JavaScript interview: Implement deepClone

medium
objects
recursion

Write deepClone(value). Copy plain objects and arrays at every level, keep Date values as new Date objects, and return primitives as they are.

Handle circular references: if an object contains itself, the copy should contain the copy.

Your code

Runs in a Web Worker in your browser. Tests use real timers, so a run takes a second or two.

FAQ