Problem, as an interviewer would state it:
"Implement deepFreeze(obj) — unlike Object.freeze(), which only freezes an object's OWN top-level properties, this must recursively freeze every nested object too, so mutation is blocked at every level."
Examples:
const frozen = deepFreeze({ a: 1, nested: { b: 2 } });
frozen.nested.b = 99; // silently fails (or throws in strict mode) -- b is still 2
Clarifying questions expected:
- Does plain
Object.freeze()alone already handle nested objects, or is that the specific real gap this question is testing? - Should arrays be recursed into the same way as plain objects?
- What should happen with a circular reference — recurse forever, or detect and stop?
Code / implementation expected: Yes — real, direct proof that mutation is blocked at the top level, a nested level, AND a deeply nested level, contrasted directly against a naive, real Object.freeze() call that fails to protect nested data.