JS Built-ins
ObjectObject.freezebeginner

Object.freeze() β€” returns same reference

πŸ“– 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() return value

Object.freeze returns the same object that was passed in β€” not a copy.

Challenge: Implement frozenRef(obj) that freezes obj and returns whether the frozen result === the original.

frozenRef({ a: 1 }) // β†’ true
πŸ’‘ Hints (1)
  • β€’ `Object.freeze` mutates and returns the same reference, unlike `Object.assign` which can take a fresh target.