---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# WeakMap

The **`WeakMap()` constructor** creates a `WeakMap` object, optionally based on a provided `Array` or other iterable object.

## Syntax

```js
new WeakMap()
new WeakMap(iterable)
```

> **Note:** `WeakMap()` can only be constructed with `new`. Attempting to call it without `new` throws a [`TypeError`](../../globals/TypeError/TypeError.mdx).

### Parameters

- `iterable`
  - : An `Array` or other object that implements the [iterable protocol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol)  that returns an iterator object that produces a two-element array-like object whose first element is a value that will be used as a `WeakMap` key and whose second element is the value to associate with that key. Each key-value pair will be added to the new `WeakMap`. null is treated as undefined.
