JavaScript Object.freeze



Object.freeze makes an object immutable by preventing the addition of new properties, the removal of existing properties, and the modification of the enumerability, configurability, and writability of existing properties. It also prevents the value of existing properties from being changed. However, it does not work recursively which means that child objects are not automatically frozen and are subject to change.

The operations following the freeze will fail silently unless the code is running in strict mode. If the code is in strict mode, a TypeError will be thrown.

var obj = {
  foo: 'foo',
  bar: [1, 2, 3],
  baz: {
    foo: 'nested-foo'


// Cannot add new properties
obj.newProperty = true;

// Cannot modify existing values or their descriptors = 'not foo';
Object.defineProperty(obj, 'foo', {
    writable: true

// Cannot delete existing properties

// Nested objects are not frozen; = 'new foo';