JS Built-ins
ObjectObject.freezeintermediate

Object.freeze() β€” shallow (nested objects not frozen)

πŸ“– Usage Example
// Make an object immutable
const obj = Object.freeze({ x: 1 })
obj.x = 99   // silently ignored
obj.x        // β†’ 1

Use Object.freeze() to make an object immutable, preventing any additions, deletions, or value changes.

Object.freeze() is shallow

Freezing is shallow: the top-level properties of the object cannot be changed, but nested objects are NOT automatically frozen.

Challenge: Implement shallowFreezeTest(obj) that freezes obj and returns whether a nested object's property can still be changed.

const o = { nested: { a: 1 } }
shallowFreezeTest(o)
o.nested.a = 99  // this WORKS β€” nested is not frozen
o.nested.a       // β†’ 99
πŸ’‘ Hints (2)
  • β€’ `Object.freeze` only prevents changes to **own properties** of the frozen object.
  • β€’ To deeply freeze an object you need to recursively freeze each nested object.