---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# Object.freeze()

The **`Object.freeze()`** method _freezes_ an object. Freezing an object [prevents extensions](../../globals/Object/preventExtensions.mdx) and makes existing properties non-writable and non-configurable. A frozen object can no longer be changed: new properties cannot be added, existing properties cannot be removed, their enumerability, configurability, writability, or value cannot be changed, and the object's prototype cannot be re-assigned. `freeze()` returns the same object that was passed in.

Freezing an object is the highest integrity level that JavaScript provides.

## Syntax

```js
Object.freeze(obj)
```

### Parameters

- `obj`
  - : The object to freeze.

### Return value

The object that was passed to the function.

## Description

Freezing an object is equivalent to [preventing extensions](../../globals/Object/preventExtensions.mdx) and then changing all existing [properties' descriptors'](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#description) `configurable` to `false` — and for data properties, `writable` to `false` as well. Nothing can be added to or removed from the properties set of a frozen object. Any attempt to do so will fail, either silently or by throwing a [`TypeError`](../../globals/TypeError/TypeError.mdx) exception (most commonly, but not exclusively, when in "strict mode").

For data properties of a frozen object, their values cannot be changed since the writable and
configurable attributes are set to false. Accessor properties (getters and setters) work the same — the property value returned by the getter may still change, and the setter can still be called without throwing errors when setting the property. Note that values
that are objects can still be modified, unless they are also frozen. As an object, an
array can be frozen; after doing so, its elements cannot be altered and no elements can
be added to or removed from the array.

`freeze()` returns the same object that was passed into the function. It
_does not_ create a frozen copy.

A `TypedArray` or a [`DataView`](../../globals/DataView/DataView.mdx) with elements will cause a [`TypeError`](../../globals/TypeError/TypeError.mdx),
as they are views over memory and will definitely cause other possible issues:

```js
Object.freeze(new Uint8Array(0)) // No elements
// Uint8Array []

Object.freeze(new Uint8Array(1)) // Has elements
// TypeError: Cannot freeze array buffer views with elements

Object.freeze(new DataView(new ArrayBuffer(32))) // No elements
// DataView {}

Object.freeze(new Float64Array(new ArrayBuffer(64), 63, 0)) // No elements
// Float64Array []

Object.freeze(new Float64Array(new ArrayBuffer(64), 32, 2)) // Has elements
// TypeError: Cannot freeze array buffer views with elements
```

Note that as the standard three properties (`buf.byteLength`,
`buf.byteOffset` and `buf.buffer`) are read-only (as are those of
an `ArrayBuffer`, there is no reason for
attempting to freeze these properties.

Unlike [`Object.seal()`](../../globals/Object/seal.mdx), existing properties in objects frozen with `Object.freeze()` are made immutable and data properties cannot be re-assigned.
