recursal/MDN huggingface dataset:
BigInt.prototype.valueOf()
==========================

Baseline Widely available
-------------------------

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.

* Learn more
* See full compatibility
* Report feedback

 The **`valueOf()`** method of `BigInt` values returns the wrapped primitive value
 of a `BigInt` object.

Try it
------

Syntax
------


```js
valueOf()
```

### Parameters

None.

### Return value

A BigInt representing the primitive value of the specified `BigInt` object.

Examples
--------

### Using `valueOf`


```js
typeof Object(1n); // object
typeof Object(1n).valueOf(); // bigint
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-bigint.prototype.valueof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `BigInt.prototype.toString()`
Promise.reject()
================

The **`Promise.reject()`** static method returns a `Promise` object that is rejected with a given reason.

Try it
------

Syntax
------


```js
Promise.reject(reason)
```

### Parameters

`reason`

Reason why this `Promise` rejected.

### Return value

A `Promise` that is rejected with the given reason.

Description
-----------

The static `Promise.reject` function returns a `Promise` that is rejected. For debugging purposes and selective error catching, it is useful to make `reason` an `instanceof` `Error`.

`Promise.reject()` is generic and supports subclassing, which means it can be called on subclasses of `Promise`, and the result will be a promise of the subclass type. To do so, the subclass's constructor must implement the same signature as the `Promise()` constructor — accepting a single `executor` function that can be called with the `resolve` and `reject` callbacks as parameters. `Promise.reject()` is essentially a shorthand for `new Promise((resolve, reject) => reject(reason))`.

Unlike `Promise.resolve()`, `Promise.reject()` always wraps `reason` in a new `Promise` object, even when `reason` is already a `Promise`.

Examples
--------

### Using the static Promise.reject() method


```js
Promise.reject(new Error("fail")).then(
  () => {
    // not called
  },
  (error) => {
    console.error(error); // Stacktrace
  },
);
```

### Rejecting with a promise

Unlike `Promise.resolve`, the `Promise.reject` method does not reuse existing `Promise` instances. It always returns a new `Promise` instance that wraps `reason`.


```js
const p = Promise.resolve(1);
const rejected = Promise.reject(p);
console.log(rejected === p); // false
rejected.catch((v) => {
  console.log(v === p); // true
});
```

### Calling reject() on a non-Promise constructor

`Promise.reject()` is a generic method. It can be called on any constructor that implements the same signature as the `Promise()` constructor. For example, we can call it on a constructor that passes it `console.log` as `reject`:


```js
class NotPromise {
  constructor(executor) {
    // The "resolve" and "reject" functions behave nothing like the
    // native promise's, but Promise.reject() calls them in the same way.
    executor(
      (value) => console.log("Resolved", value),
      (reason) => console.log("Rejected", reason),
    );
  }
}

Promise.reject.call(NotPromise, "foo"); // Logs "Rejected foo"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-promise.reject |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Promise`
Promise.allSettled()
====================

The **`Promise.allSettled()`** static method takes an iterable of promises as input and returns a single `Promise`. This returned promise fulfills when all of the input's promises settle (including when an empty iterable is passed), with an array of objects that describe the outcome of each promise.

Try it
------

Syntax
------


```js
Promise.allSettled(iterable)
```

### Parameters

`iterable`

An iterable (such as an `Array`) of promises.

### Return value

A `Promise` that is:

* **Already fulfilled**, if the `iterable` passed is empty.
* **Asynchronously fulfilled**, when all promises in the given `iterable` have settled (either fulfilled or rejected). The fulfillment value is an array of objects, each describing the outcome of one promise in the `iterable`, in the order of the promises passed, regardless of completion order. Each outcome object has the following properties:

`status`

A string, either `"fulfilled"` or `"rejected"`, indicating the eventual state of the promise.

`value`

Only present if `status` is `"fulfilled"`. The value that the promise was fulfilled with.

`reason`

Only present if `status` is `"rejected"`. The reason that the promise was rejected with.

If the `iterable` passed is non-empty but contains no pending promises, the returned promise is still asynchronously (instead of synchronously) fulfilled.
Description
-----------

The `Promise.allSettled()` method is one of the promise concurrency methods. `Promise.allSettled()` is typically used when you have multiple asynchronous tasks that are not dependent on one another to complete successfully, or you'd always like to know the result of each promise.

In comparison, the Promise returned by `Promise.all()` may be more appropriate if the tasks are dependent on each other, or if you'd like to immediately reject upon any of them rejecting.

Examples
--------

### Using Promise.allSettled()


```js
Promise.allSettled([
  Promise.resolve(33),
  new Promise((resolve) => setTimeout(() => resolve(66), 0)),
  99,
  Promise.reject(new Error("an error")),
]).then((values) => console.log(values));

// [
// { status: 'fulfilled', value: 33 },
// { status: 'fulfilled', value: 66 },
// { status: 'fulfilled', value: 99 },
// { status: 'rejected', reason: Error: an error }
// ]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-promise.allsettled |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Promise.allSettled` in `core-js`
* Using promises guide
* Graceful asynchronous programming with promises
* `Promise`
* `Promise.all()`
* `Promise.any()`
* `Promise.race()`
Map.prototype.clear()
=====================

The **`clear()`** method of `Map` instances removes all elements from this map.

Try it
------

Syntax
------


```js
clear()
```

### Parameters

None.

### Return value

None (`undefined`).

Examples
--------

### Using clear()


```js
const myMap = new Map();
myMap.set("bar", "baz");
myMap.set(1, "foo");

console.log(myMap.size); // 2
console.log(myMap.has("bar")); // true

myMap.clear();

console.log(myMap.size); // 0
console.log(myMap.has("bar")); // false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.clear |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
Map.prototype.entries()
=======================

The **`entries()`** method of `Map` instances returns a new *map iterator* object that contains the `[key, value]` pairs for each element in this map in insertion order.

Try it
------

Syntax
------


```js
entries()
```

### Parameters

None.

### Return value

A new iterable iterator object.

Examples
--------

### Using entries()


```js
const myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

const mapIter = myMap.entries();

console.log(mapIter.next().value); // ["0", "foo"]
console.log(mapIter.next().value); // [1, "bar"]
console.log(mapIter.next().value); // [Object, "baz"]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.entries |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map.prototype.keys()`
* `Map.prototype.values()`
Map.prototype.delete()
======================

 The **`delete()`** method of `Map` instances removes the specified element from this map by
 key.

Try it
------

Syntax
------


```js
mapInstance.delete(key)
```

### Parameters

`key`

The key of the element to remove from the `Map` object.

### Return value

`true` if an element in the `Map` object existed and has been removed, or
 `false` if the element does not exist.

Examples
--------

### Using delete()


```js
const myMap = new Map();
myMap.set("bar", "foo");

console.log(myMap.delete("bar")); // Returns true. Successfully removed.
console.log(myMap.has("bar")); // Returns false. The "bar" element is no longer present.
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.delete |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
Map.prototype.keys()
====================

The **`keys()`** method of `Map` instances returns a new *map iterator* object that contains the keys for each element in this map in insertion order.

Try it
------

Syntax
------


```js
keys()
```

### Parameters

None.

### Return value

A new iterable iterator object.

Examples
--------

### Using keys()


```js
const myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

const mapIter = myMap.keys();

console.log(mapIter.next().value); // "0"
console.log(mapIter.next().value); // 1
console.log(mapIter.next().value); // {}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.keys |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map.prototype.entries()`
* `Map.prototype.values()`
Map.prototype[@@iterator]()
===========================

The **`[@@iterator]()`** method of `Map` instances implements the iterable protocol and allows `Map` objects to be consumed by most syntaxes expecting iterables, such as the spread syntax and `for...of` loops. It returns a map iterator object that yields the key-value pairs of the map in insertion order.

The initial value of this property is the same function object as the initial value of the `Map.prototype.entries` property.

Try it
------

Syntax
------


```js
map[Symbol.iterator]()
```

### Parameters

None.

### Return value

The same return value as `Map.prototype.entries()`: a new iterable iterator object that yields the key-value pairs of the map.

Examples
--------

### Iteration using for...of loop

Note that you seldom need to call this method directly. The existence of the `@@iterator` method makes `Map` objects iterable, and iterating syntaxes like the `for...of` loop automatically call this method to obtain the iterator to loop over.


```js
const myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

for (const entry of myMap) {
  console.log(entry);
}
// ["0", "foo"]
// [1, "bar"]
// [{}, "baz"]

for (const [key, value] of myMap) {
  console.log(`${key}: ${value}`);
}
// 0: foo
// 1: bar
// [Object]: baz
```

### Manually hand-rolling the iterator

You may still manually call the `next()` method of the returned iterator object to achieve maximum control over the iteration process.


```js
const myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

const mapIter = myMap[Symbol.iterator]();

console.log(mapIter.next().value); // ["0", "foo"]
console.log(mapIter.next().value); // [1, "bar"]
console.log(mapIter.next().value); // [Object, "baz"]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype-@@iterator |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
* `Map.prototype.entries()`
* `Map.prototype.keys()`
* `Map.prototype.values()`
* `Symbol.iterator`
* Iteration protocols
Map() constructor
=================

The **`Map()`** constructor creates `Map` objects.

Syntax
------


```js
new Map()
new Map(iterable)
```


**Note:** `Map()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`iterable` Optional

 An `Array` or other
 iterable object
 whose elements are key-value pairs. (For example, arrays with two elements,
 such as `[[ 1, 'one' ],[ 2, 'two' ]]`.) Each key-value pair is added to the
 new `Map`.


Examples
--------

### Creating a new Map


```js
const myMap = new Map([
  [1, "one"],
  [2, "two"],
  [3, "three"],
]);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill for `Map` in `core-js`
* `Set`
* `WeakMap`
* `WeakSet`
Map.prototype.set()
===================

The **`set()`** method of `Map` instances adds or updates an entry in this map with a specified key and a value.

Try it
------

Syntax
------


```js
set(key, value)
```

### Parameters

`key`

The key of the element to add to the `Map` object. The key may be any JavaScript type (any primitive value or any type of JavaScript object).

`value`

The value of the element to add to the `Map` object. The value may be any JavaScript type (any primitive value or any type of JavaScript object).

### Return value

The `Map` object.

Examples
--------

### Using set()


```js
const myMap = new Map();

// Add new elements to the map
myMap.set("bar", "foo");
myMap.set(1, "foobar");

// Update an element in the map
myMap.set("bar", "baz");
```

### Using the set() with chaining

 Since the `set()` method returns back the same `Map` object, you can chain the
 method call like below:


```js
// Add new elements to the map with chaining.
myMap.set("bar", "foo").set(1, "foobar").set(2, "baz");
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.set |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
* `Map.prototype.get()`
* `Map.prototype.has()`
Map.prototype.size
==================

The **`size`** accessor property of `Map` instances returns the number of elements in this map.

Try it
------

Description
-----------

 The value of `size` is an integer representing how many entries the `Map` object
 has. A set accessor function for `size` is `undefined`; you can not change this
 property.

Examples
--------

### Using size


```js
const myMap = new Map();
myMap.set("a", "alpha");
myMap.set("b", "beta");
myMap.set("g", "gamma");

console.log(myMap.size); // 3
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-map.prototype.size |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
Map.prototype.values()
======================

The **`values()`** method of `Map` instances returns a new *map iterator* object that contains the values for each element in this map in insertion order.

Try it
------

Syntax
------


```js
values()
```

### Parameters

None.

### Return value

A new iterable iterator object.

Examples
--------

### Using values()


```js
const myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

const mapIter = myMap.values();

console.log(mapIter.next().value); // "foo"
console.log(mapIter.next().value); // "bar"
console.log(mapIter.next().value); // "baz"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.values |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map.prototype.entries()`
* `Map.prototype.keys()`
Map.prototype.forEach()
=======================

 The **`forEach()`** method of `Map` instances executes a provided function once per each key/value
 pair in this map, in insertion order.

Try it
------

Syntax
------


```js
forEach(callbackFn)
forEach(callbackFn, thisArg)
```

### Parameters

`callbackFn`

A function to execute for each entry in the map. The function is called with the following arguments:

`value`

Value of each iteration.

`key`

Key of each iteration.

`map`

The map being iterated.


`thisArg` Optional

A value to use as `this` when executing `callbackFn`.

### Return value

None (`undefined`).

Description
-----------

 The `forEach` method executes the provided `callback` once for each key of the
 map which actually exist. It is not invoked for keys which have been deleted.
 However, it is executed for values which are present but have the value
 `undefined`.

`callback` is invoked with **three arguments**:

* the entry's `value`
* the entry's `key`
* the **`Map` object** being traversed

 If a `thisArg` parameter is provided to `forEach`, it will be passed to
 `callback` when invoked, for use as its `this` value. Otherwise, the value
 `undefined` will be passed for use as its `this` value. The `this` value
 ultimately observable by `callback` is determined according to
 the usual rules for determining the `this` seen by a function.

 Each value is visited once, except in the case when it was deleted and re-added
 before `forEach` has finished. `callback` is not invoked for values deleted
 before being visited. New values added before `forEach` has finished will be
 visited.

Examples
--------

### Printing the contents of a Map object

The following code logs a line for each element in an `Map` object:


```js
function logMapElements(value, key, map) {
  console.log(`map.get('${key}') = ${value}`);
}
new Map([
  ["foo", 3],
  ["bar", {}],
  ["baz", undefined],
]).forEach(logMapElements);
// Logs:
// "map.get('foo') = 3"
// "map.get('bar') = [object Object]"
// "map.get('baz') = undefined"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.foreach |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Array.prototype.forEach()`
* `Set.prototype.forEach()`
Map.prototype.has()
===================

 The **`has()`** method of `Map` instances returns a boolean indicating whether an element with the
 specified key exists in this map or not.

Try it
------

Syntax
------


```js
has(key)
```

### Parameters

`key`

The key of the element to test for presence in the `Map` object.

### Return value

`true` if an element with the specified key exists in the `Map` object;
 otherwise `false`.

Examples
--------

### Using has()


```js
const myMap = new Map();
myMap.set("bar", "foo");

console.log(myMap.has("bar")); // true
console.log(myMap.has("baz")); // false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.has |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
* `Map.prototype.set()`
* `Map.prototype.get()`
Map.prototype.get()
===================

 The **`get()`** method of `Map` instances returns a specified element from this map. If the
 value that is associated to the provided key is an object, then you will get a
 reference to that object and any change made to that object will effectively
 modify it inside the `Map` object.

Try it
------

Syntax
------


```js
get(key)
```

### Parameters

`key`

The key of the element to return from the `Map` object.

### Return value

 The element associated with the specified key, or
 `undefined` if the key can't be found in the `Map` object.

Examples
--------

### Using get()


```js
const myMap = new Map();
myMap.set("bar", "foo");

console.log(myMap.get("bar")); // Returns "foo"
console.log(myMap.get("baz")); // Returns undefined
```

### Using get() to retrieve a reference to an object


```js
const arr = [];
const myMap = new Map();
myMap.set("bar", arr);

myMap.get("bar").push("foo");

console.log(arr); // ["foo"]
console.log(myMap.get("bar")); // ["foo"]
```


Note that the map holding a reference to the original object effectively means the object cannot be garbage-collected, which may lead to unexpected memory issues. If you want the object stored in the map to have the same lifespan as the original one, consider using a `WeakMap`.

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-map.prototype.get |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
* `Map.prototype.set()`
* `Map.prototype.has()`
Map[@@species]
==============

The **`Map[@@species]`** static accessor property is an unused accessor property specifying how to copy `Map` objects.

Syntax
------


```js
Map[Symbol.species]
```

### Return value

The value of the constructor (`this`) on which `get @@species` was called. The return value is used to construct copied `Map` instances.

Description
-----------

The `@@species` accessor property returns the default constructor for `Map` objects. Subclass constructors may override it to change the constructor assignment.

**Note:** This property is currently unused by all `Map` methods.

Examples
--------

### Species in ordinary objects

The `@@species` property returns the default constructor function, which is the `Map` constructor for `Map`.


```js
Map[Symbol.species]; // function Map()
```

### Species in derived objects

In an instance of a custom `Map` subclass, such as `MyMap`, the `MyMap` species is the `MyMap` constructor. However, you might want to overwrite this, in order to return parent `Map` objects in your derived class methods:


```js
class MyMap extends Map {
  // Overwrite MyMap species to the parent Map constructor
  static get [Symbol.species]() {
    return Map;
  }
}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-map-@@species |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Map`
* `Symbol.species`