GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

WeakRef.prototype.deref()

The deref() method of WeakRef instances returns this WeakRef's target value, or undefined if the target value has been garbage-collected.

The **`deref()`** method of WeakRef instances returns this `WeakRef`'s target value, or `undefined` if the target value has been garbage-collected.

## Syntax

```js-nolint
deref()
```

### Parameters

None.

### Return value

The target value of the WeakRef, which is either an object or a [non-registered symbol](/docs/Web/JavaScript/Reference/Global_Objects/Symbol#shared_symbols_in_the_global_symbol_registry). Returns `undefined` if the value has been garbage-collected.

## Description

See the [Notes on WeakRefs](/docs/Web/JavaScript/Reference/Global_Objects/WeakRef#notes_on_weakrefs) section of the WeakRef page for some important notes.

## Examples

### Using deref()

See the [Examples](/docs/Web/JavaScript/Reference/Global_Objects/WeakRef#examples)
section of the WeakRef page for the complete example.

```js
const tick = () => {
// Get the element from the weak reference, if it still exists
const element = this.ref.deref();
if (element) {
element.textContent = ++this.count;
} else {
// The element doesn't exist anymore
console.log("The element is gone.");
this.stop();
this.ref = null;
}
};
```

## Specifications

## Browser compatibility

## See also

- WeakRef

source: MDN Web Docs mirror · page

Cite this

"WeakRef.prototype.deref()". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·