recursal/MDN huggingface dataset:
Symbol.prototype.toString()
===========================

The **`toString()`** method of `Symbol` values returns a string representing this symbol value.

Try it
------

Syntax
------


```js
toString()
```

### Parameters

None.

### Return value

A string representing the specified symbol value.

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

 The `Symbol` object overrides the `toString` method of `Object`; it does not inherit
 `Object.prototype.toString()`. For `Symbol` values, the `toString` method returns a descriptive string in the form `"Symbol(description)"`, where `description` is the symbol's description.

The `toString()` method requires its `this` value to be a `Symbol` primitive or wrapper object. It throws a `TypeError` for other `this` values without attempting to coerce them to symbol values.

Because `Symbol` has a `[@@toPrimitive]()` method, that method always takes priority over `toString()` when a `Symbol` object is coerced to a string. However, because `Symbol.prototype[@@toPrimitive]()` returns a symbol primitive, and symbol primitives throw a `TypeError` when implicitly converted to a string, the `toString()` method is never implicitly called by the language. To stringify a symbol, you must explicitly call its `toString()` method or use the `String()` function.

Examples
--------

### Using toString()


```js
Symbol("desc").toString(); // "Symbol(desc)"

// well-known symbols
Symbol.iterator.toString(); // "Symbol(Symbol.iterator)"

// global symbols
Symbol.for("foo").toString(); // "Symbol(foo)"
```

### Implicitly calling toString()

The only way to make JavaScript implicitly call `toString()` instead of `[@@toPrimitive]()` on a symbol wrapper object is by deleting the `@@toPrimitive` method first.

**Warning:** You should not do this in practice. Never mutate built-in objects unless you know exactly what you're doing.


```js
delete Symbol.prototype[Symbol.toPrimitive];
console.log(`${Object(Symbol("foo"))}`); // "Symbol(foo)"
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-symbol.prototype.tostring |

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

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

See also
--------

* `Object.prototype.toString()`
Symbol.match
============

The **`Symbol.match`** static data property represents the well-known symbol `@@match`. The `String.prototype.match()` method looks up this symbol on its first argument for the method used to match an input string against the current object. This symbol is also used to determine if an object should be treated as a regex.

For more information, see `RegExp.prototype[@@match]()` and `String.prototype.match()`.

Try it
------

Value
-----

The well-known symbol `@@match`.

| Property attributes of `Symbol.match` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

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

This function is also used to identify if objects have the behavior of regular expressions. For example, the methods `String.prototype.startsWith()`, `String.prototype.endsWith()` and `String.prototype.includes()`, check if their first argument is a regular expression and will throw a `TypeError` if they are. Now, if the `match` symbol is set to `false` (or a Falsy value except `undefined`), it indicates that the object is not intended to be used as a regular expression object.

Examples
--------

### Marking a RegExp as not a regex

The following code will throw a `TypeError`:


```js
"/bar/".startsWith(/bar/);

// Throws TypeError, as /bar/ is a regular expression
// and Symbol.match is not modified.
```


However, if you set `Symbol.match` to `false`, the object will be considered as not a regular expression object. The methods `startsWith` and `endsWith` won't throw a `TypeError` as a consequence.


```js
const re = /foo/;
re[Symbol.match] = false;
"/foo/".startsWith(re); // true
"/baz/".endsWith(re); // false
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-symbol.match |

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

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

See also
--------

* Polyfill of `Symbol.match` in `core-js`
* `Symbol.matchAll`
* `Symbol.replace`
* `Symbol.search`
* `Symbol.split`
* `String.prototype.match()`
* `RegExp.prototype[@@match]()`
Symbol.prototype.valueOf()
==========================

The **`valueOf()`** method of `Symbol` values returns this symbol value.

Try it
------

Syntax
------


```js
valueOf()
```

### Parameters

None.

### Return value

The primitive value of the specified `Symbol` object.

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

The `valueOf()` method of `Symbol` returns the primitive value of a Symbol object as a Symbol data type.

JavaScript calls the `valueOf()` method to convert an object to a primitive value. You rarely need to invoke the `valueOf()` method yourself; JavaScript automatically invokes it when encountering an object where a primitive value is expected.

Examples
--------

### Using valueOf()


```js
const sym = Symbol("example");
sym === sym.valueOf(); // true
```

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

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

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

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

See also
--------

* `Object.prototype.valueOf()`
Symbol.matchAll
===============

The **`Symbol.matchAll`** static data property represents the well-known symbol `@@matchAll`. The `String.prototype.matchAll()` method looks up this symbol on its first argument for the method that returns an iterator, that yields matches of the current object against a string.

For more information, see `RegExp.prototype[@@matchAll]()` and `String.prototype.matchAll()`.

Try it
------

Value
-----

The well-known symbol `@@matchAll`.

| Property attributes of `Symbol.matchAll` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

Examples
--------

### Using Symbol.matchAll


```js
const str = "2016-01-02|2019-03-07";

const numbers = {
  \*[Symbol.matchAll](str) {
    for (const n of str.matchAll(/[0-9]+/g)) yield n[0];
  },
};

console.log(Array.from(str.matchAll(numbers)));
// ["2016", "01", "02", "2019", "03", "07"]
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-symbol.matchall |

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

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

See also
--------

* Polyfill of `Symbol.matchAll` in `core-js`
* `Symbol.match`
* `Symbol.replace`
* `Symbol.search`
* `Symbol.split`
* `String.prototype.matchAll()`
* `RegExp.prototype[@@matchAll]()`
Symbol.iterator
===============

The **`Symbol.iterator`** static data property represents the well-known symbol `@@iterator`. The iterable protocol looks up this symbol for the method that returns the iterator for an object. In order for an object to be iterable, it must have an `@@iterator` key.

Try it
------

Value
-----

The well-known symbol `@@iterator`.

| Property attributes of `Symbol.iterator` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

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

Whenever an object needs to be iterated (such as at the beginning of a `for...of` loop), its `@@iterator` method is called with no arguments, and the returned **iterator** is used to obtain the values to be iterated.

Some built-in types have a default iteration behavior, while other types (such as `Object`) do not. Some built-in types with a `@@iterator` method are:

* `Array.prototype[@@iterator]()`
* `TypedArray.prototype[@@iterator]()`
* `String.prototype[@@iterator]()`
* `Map.prototype[@@iterator]()`
* `Set.prototype[@@iterator]()`

See also Iteration protocols for more information.

Examples
--------

### User-defined iterables

We can make our own iterables like this:


```js
const myIterable = {};
myIterable[Symbol.iterator] = function\* () {
  yield 1;
  yield 2;
  yield 3;
};
[...myIterable]; // [1, 2, 3]
```


Or iterables can be defined directly inside a class or object using a computed property:


```js
class Foo {
  \*[Symbol.iterator]() {
    yield 1;
    yield 2;
    yield 3;
  }
}

const someObj = {
  \*[Symbol.iterator]() {
    yield "a";
    yield "b";
  },
};

console.log(...new Foo()); // 1, 2, 3
console.log(...someObj); // 'a', 'b'
```

### Non-well-formed iterables

If an iterable's `@@iterator` method does not return an iterator object, then it is a non-well-formed iterable. Using it as such is likely to result in runtime exceptions or buggy behavior:


```js
const nonWellFormedIterable = {};
nonWellFormedIterable[Symbol.iterator] = () => 1;
[...nonWellFormedIterable]; // TypeError: [Symbol.iterator]() returned a non-object value
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-symbol.iterator |

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

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

See also
--------

* Polyfill of `Symbol.iterator` in `core-js`
* Iteration protocols
* `Array.prototype[@@iterator]()`
* `TypedArray.prototype[@@iterator]()`
* `String.prototype[@@iterator]()`
* `Map.prototype[@@iterator]()`
* `Set.prototype[@@iterator]()`
* `arguments[@@iterator]()`
* `Segments.prototype[@@iterator]()`
Symbol.replace
==============

The **`Symbol.replace`** static data property represents the well-known symbol `@@replace`. The `String.prototype.replace()` method looks up this symbol on its first argument for the method that replaces substrings matched by the current object.

For more information, see `RegExp.prototype[@@replace]()` and `String.prototype.replace()`.

Try it
------

Value
-----

The well-known symbol `@@replace`.

| Property attributes of `Symbol.replace` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

Examples
--------

### Using Symbol.replace


```js
class CustomReplacer {
  constructor(value) {
    this.value = value;
  }
  [Symbol.replace](string) {
    return string.replace(this.value, "#!@?");
  }
}

console.log("football".replace(new CustomReplacer("foo"))); // "#!@?tball"
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-symbol.replace |

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

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

See also
--------

* Polyfill of `Symbol.replace` in `core-js`
* `Symbol.match`
* `Symbol.matchAll`
* `Symbol.search`
* `Symbol.split`
* `String.prototype.replace()`
* `RegExp.prototype[@@replace]()`
AsyncGeneratorFunction() constructor
====================================

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

Note that `AsyncGeneratorFunction` is not a global object. It could be obtained by evaluating the following code.


```js
const AsyncGeneratorFunction = async function\* () {}.constructor;
```


The `AsyncGeneratorFunction()` constructor is not intended to be used directly, and all caveats mentioned in the `Function()` description apply to `AsyncGeneratorFunction()`.

Syntax
------


```js
new AsyncGeneratorFunction(functionBody)
new AsyncGeneratorFunction(arg1, functionBody)
new AsyncGeneratorFunction(arg1, arg2, functionBody)
new AsyncGeneratorFunction(arg1, arg2, /\* …, \*/ argN, functionBody)

AsyncGeneratorFunction(functionBody)
AsyncGeneratorFunction(arg1, functionBody)
AsyncGeneratorFunction(arg1, arg2, functionBody)
AsyncGeneratorFunction(arg1, arg2, /\* …, \*/ argN, functionBody)
```


**Note:** `AsyncGeneratorFunction()` can be called with or without `new`. Both create a new `AsyncGeneratorFunction` instance.

### Parameters

See `Function()`.

Examples
--------

### Using the constructor

The following example uses the `AsyncGeneratorFunction` constructor to create an async generator function.


```js
const AsyncGeneratorFunction = async function\* () {}.constructor;
const createAsyncGenerator = new AsyncGeneratorFunction("a", "yield a \* 2");
const asyncGen = createAsyncGenerator(10);
asyncGen.next().then((res) => console.log(res.value)); // 20
```

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

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

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

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

See also
--------

* `async function*`
* `async function*` expression
* `Function()` constructor
* Iterators and generators guide
* Functions
ArrayBuffer.prototype.transferToFixedLength()
=============================================

The **`transferToFixedLength()`** method of `ArrayBuffer` instances creates a new non-resizable `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.

Syntax
------


```js
transferToFixedLength()
transferToFixedLength(newByteLength)
```

### Parameters

`newByteLength`

The `byteLength` of the new `ArrayBuffer`. Defaults to the `byteLength` of this `ArrayBuffer`.

* If `newByteLength` is smaller than the `byteLength` of this `ArrayBuffer`, the "overflowing" bytes are dropped.
* If `newByteLength` is larger than the `byteLength` of this `ArrayBuffer`, the extra bytes are filled with zeros.

### Return value

A new `ArrayBuffer` object. Its contents are initialized to the contents of this `ArrayBuffer`, and extra bytes, if any, are filled with zeros. The new `ArrayBuffer` is always non-resizable. The original `ArrayBuffer` is detached.

### Exceptions

`TypeError`

Thrown if this `ArrayBuffer` is already detached.

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

Unlike `transfer()`, `transferToFixedLength()` always creates a non-resizable `ArrayBuffer`. This means `newByteLength` can be larger than the `maxByteLength`, even if this `ArrayBuffer` is resizable. See transferring ArrayBuffers for more information.

Examples
--------

### Transferring a resizable ArrayBuffer to fixed-length


```js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const view = new Uint8Array(buffer);
view[1] = 2;
view[7] = 4;

const buffer2 = buffer.transferToFixedLength();
console.log(buffer2.byteLength); // 8
console.log(buffer2.resizable); // false
const view2 = new Uint8Array(buffer2);
console.log(view2[1]); // 2
console.log(view2[7]); // 4
```


Using `transferToFixedLength`, `newByteLength` can be larger than the `maxByteLength` of the original `ArrayBuffer`.


```js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const view = new Uint8Array(buffer);
view[1] = 2;
view[7] = 4;

const buffer2 = buffer.transferToFixedLength(20);
console.log(buffer2.byteLength); // 20
console.log(buffer2.resizable); // false
const view2 = new Uint8Array(buffer2);
console.log(view2[1]); // 2
console.log(view2[7]); // 4
```

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

| Specification |
| --- |
| ArrayBuffer transfer # sec-arraybuffer.prototype.transfertofixedlength |

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

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

See also
--------

* Polyfill of `ArrayBuffer.prototype.transferToFixedLength()` in `core-js`
* `ArrayBuffer`
* `ArrayBuffer.prototype.detached`
* `ArrayBuffer.prototype.transfer()`
ArrayBuffer.prototype.maxByteLength
===================================

The **`maxByteLength`** accessor property of `ArrayBuffer` instances returns the maximum length (in bytes) that this array buffer can be resized to.

Try it
------

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

The `maxByteLength` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when the array is constructed, set via the `maxByteLength` option of the `ArrayBuffer()` constructor, and cannot be changed.

This property returns 0 if this `ArrayBuffer` has been detached. If this `ArrayBuffer` was constructed without specifying a `maxByteLength` value, this property returns a value equal to the value of the `ArrayBuffer`'s `byteLength`.

Examples
--------

### Using maxByteLength

In this example, we create an 8-byte buffer that is resizable to a max length of 16 bytes, then return its `maxByteLength`:


```js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });

buffer.maxByteLength; // 16
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-arraybuffer.prototype.maxbytelength |

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

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

See also
--------

* `ArrayBuffer`
* `ArrayBuffer.prototype.byteLength`
* `ArrayBuffer.prototype.resize()`
ArrayBuffer.prototype.byteLength
================================

The **`byteLength`** accessor property of `ArrayBuffer` instances returns the length (in bytes) of this array buffer.

Try it
------

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

The `byteLength` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when the array is constructed and cannot be changed. This property returns 0 if this `ArrayBuffer` has been detached.

Examples
--------

### Using byteLength


```js
const buffer = new ArrayBuffer(8);
buffer.byteLength; // 8
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-arraybuffer.prototype.bytelength |

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

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

See also
--------

* `ArrayBuffer`
ArrayBuffer.prototype.resizable
===============================

The **`resizable`** accessor property of `ArrayBuffer` instances returns whether this array buffer can be resized or not.

Try it
------

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

The `resizable` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when the array is constructed. If the `maxByteLength` option was set in the constructor, `resizable` will return `true`; if not, it will return `false`.

Examples
--------

### Using resizable

In this example, we create a 8-byte buffer that is resizable to a max length of 16 bytes, then check its `resizable` property, resizing it if `resizable` returns `true`:


```js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });

if (buffer.resizable) {
  console.log("Buffer is resizable!");
  buffer.resize(12);
}
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-arraybuffer.prototype.resizable |

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

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

See also
--------

* `ArrayBuffer`
* `ArrayBuffer.prototype.maxByteLength`
* `ArrayBuffer.prototype.resize()`
ArrayBuffer.isView()
====================

 The **`ArrayBuffer.isView()`** static method determines whether the
 passed value is one of the `ArrayBuffer` views,
 such as typed array objects
 or a `DataView`.

Try it
------

Syntax
------


```js
ArrayBuffer.isView(value)
```

### Parameters

`value`

The value to be checked.

### Return value

`true` if the given argument is one of the `ArrayBuffer` views;
 otherwise, `false`.

Examples
--------

### Using isView


```js
ArrayBuffer.isView(); // false
ArrayBuffer.isView([]); // false
ArrayBuffer.isView({}); // false
ArrayBuffer.isView(null); // false
ArrayBuffer.isView(undefined); // false
ArrayBuffer.isView(new ArrayBuffer(10)); // false

ArrayBuffer.isView(new Uint8Array()); // true
ArrayBuffer.isView(new Float32Array()); // true
ArrayBuffer.isView(new Int8Array(10).subarray(0, 3)); // true

const buffer = new ArrayBuffer(2);
const dv = new DataView(buffer);
ArrayBuffer.isView(dv); // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-arraybuffer.isview |

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

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

See also
--------

* JavaScript typed arrays guide
ArrayBuffer[@@species]
======================

The **`ArrayBuffer[@@species]`** static accessor property returns the constructor used to construct return values from array buffer methods.

**Warning:** The existence of `@@species` allows execution of arbitrary code and may create security vulnerabilities. It also makes certain optimizations much harder. Engine implementers are investigating whether to remove this feature. Avoid relying on it if possible.

Syntax
------


```js
ArrayBuffer[Symbol.species]
```

### Return value

The value of the constructor (`this`) on which `get @@species` was called. The return value is used to construct return values from array buffer methods that create new array buffers.

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

The `@@species` accessor property returns the default constructor for `ArrayBuffer` objects. Subclass constructors may override it to change the constructor assignment. The default implementation is basically:


```js
// Hypothetical underlying implementation for illustration
class ArrayBuffer {
  static get [Symbol.species]() {
    return this;
  }
}
```


Because of this polymorphic implementation, `@@species` of derived subclasses would also return the constructor itself by default.


```js
class SubArrayBuffer extends ArrayBuffer {}
SubArrayBuffer[Symbol.species] === SubArrayBuffer; // true
```


When calling array buffer methods that do not mutate the existing object but return a new array buffer instance (for example, `slice()`), the object's `constructor[@@species]` will be accessed. The returned constructor will be used to construct the return value of the array buffer method.

Examples
--------

### Species in ordinary objects

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


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

### Species in derived objects

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


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

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

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

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

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

See also
--------

* `ArrayBuffer`
* `Symbol.species`