Bayu’s cabinets: Object.freeze padlocks an object, but how deep? Run your own statements, in a plain script or with use strict. An interactive Object.freeze…
Why it matters
"I froze it, why did it still change?" This bug comes from shallow freezing. Knowing it means understanding why immutable state needs deepFreeze or a special structure, and why a plain script fails silently on frozen objects.
The key idea
Freeze is shallow: one layer only
Common mistakes
o.nested.x = 1 still works after freezing Freeze is one layer deep. Use a recursive deepFreeze for every layer.
Writing to a frozen property does not error, but does nothing either In a plain script the refusal is silent. Use 'use strict' (or a module) so it throws a TypeError and you notice.
Using const, the object’s contents still changeconst locks the name (it cannot point to another object), not the contents. To lock the contents, use Object.freeze.
Try it in this playground
Write to rekening.saldo after freezing The account’s drawers are frozen: the write is refused, the balance stays 100.
Change rekening.alamat.kota after freezing It works: the address box was not padlocked. This is shallow freezing.
Use deepFreeze, try again Now the address box refuses too.
Add rekening.baru to the frozen account Freeze refuses new drawers too, not only changes.