Skip to content

QuizNot attempted

Object.freeze

const cfg = Object.freeze({ a: { b: 1 } }); cfg.a.b = 2; What happens?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • cfg.a.b becomes 2: freeze is shallow
  • Object.freeze is shallow: it locks cfg's own properties, but cfg.a is a separate, unfrozen object, so writing cfg.a.b succeeds.
  • Not TypeError in strict mode: only writes to a frozen object's own properties (e.g.
  • cfg.a = {}) throw.
  • Not 'stays 1 silently': that is sloppy-mode behaviour for writes to frozen properties, which this isn't.
  • Not 'cfg is unfrozen': freezing is permanent.
  • Use a recursive deepFreeze for nested data.