---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# FinalizationRegistry.prototype.register()

The `register()` method registers an object with a
`FinalizationRegistry` instance so that if the object is garbage-collected,
the registry's callback may get called.

## Syntax

```js
register(target, heldValue)
register(target, heldValue, unregisterToken)
```

### Parameters

- `target`
  - : The target object to register.
- `heldValue`
  - : The value to pass to the finalizer for this object. This cannot be the `target` object but can be anything else, including functions and primitives.
- `unregisterToken` _**optional**_
  - : A token that may be used with the `unregister` method later to unregister
    the target object. If provided (and not `undefined`), this must be an
    object. If not provided, the target cannot be unregistered.

### Return value

`undefined`.

### Exceptions

- [`TypeError`](../../../globals/TypeError/TypeError.mdx)
  - : Thrown when one of the following condition is met:
    - `target` is not an object (object as opposed to primitives; functions are objects as well)
    - `target` is the same as `heldvalue` (`target === heldValue`)
    - `unregisterToken` is not an object

## Description

See the [Avoid where possible](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry#avoid_where_possible)
and [Notes on cleanup callbacks](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry#notes_on_cleanup_callbacks)
sections of the `FinalizationRegistry` page for important caveats.
