whatstheoutput_

#100: Object.freeze and a nested object

Topic: objects · Difficulty: ★★

const obj = Object.freeze({ nested: { value: 1 } });
obj.nested.value = 2;
obj.top = 'new';
console.log(obj.nested.value, obj.top);

Output

2 undefined

Why

Object.freeze only locks the object's OWN top-level property slots: you can't reassign obj.nested to something else, and you can't add a new property like obj.top (that silent failure is why obj.top stays undefined). But the freeze doesn't reach any deeper — the value stored at obj.nested is a separate, entirely unfrozen object, so its own 'value' property can still be reassigned freely. Freezing is exactly one level deep, never recursive.

More objects puzzles

Play today's puzzle →