recursal/MDN huggingface dataset:
DataView.prototype.getInt32()
=============================

The **`getInt32()`** method of `DataView` instances reads 4 bytes starting at the specified byte offset of this `DataView` and interprets them as a 32-bit signed integer. There is no alignment constraint; multi-byte values may be fetched from any offset within bounds.

Try it
------

Syntax
------


```js
getInt32(byteOffset)
getInt32(byteOffset, littleEndian)
```

### Parameters

`byteOffset`

The offset, in bytes, from the start of the view to read the data from.

`littleEndian` Optional

Indicates whether the data is stored in little- or big-endian format. If `false` or `undefined`, a big-endian value is read.

### Return value

An integer from -2147483648 to 2147483647, inclusive.

### Exceptions

`RangeError`

Thrown if the `byteOffset` is set such that it would read beyond the end of the view.

Examples
--------

### Using getInt32()


```js
const { buffer } = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
const dataview = new DataView(buffer);
console.log(dataview.getInt32(1)); // 16909060
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-dataview.prototype.getint32 |

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

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

See also
--------

* JavaScript typed arrays guide
* `DataView`
* `ArrayBuffer`
* `Int32Array`
DataView.prototype.getBigUint64()
=================================

The **`getBigUint64()`** method of `DataView` instances reads 8 bytes starting at the specified byte offset of this `DataView` and interprets them as a 64-bit unsigned integer. There is no alignment constraint; multi-byte values may be fetched from any offset within bounds.

Try it
------

Syntax
------


```js
getBigUint64(byteOffset)
getBigUint64(byteOffset, littleEndian)
```

### Parameters

`byteOffset`

The offset, in bytes, from the start of the view to read the data from.

`littleEndian` Optional

Indicates whether the data is stored in little- or big-endian format. If `false` or `undefined`, a big-endian value is read.

### Return value

A `BigInt` from 0 to 264-1, inclusive.

### Exceptions

`RangeError`

Thrown if the `byteOffset` is set such that it would read beyond the end of the view.

Examples
--------

### Using getBigUint64()


```js
const { buffer } = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
const dataview = new DataView(buffer);
console.log(dataview.getBigUint64(1)); // 72623859790382856n
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-dataview.prototype.getbiguint64 |

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

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

See also
--------

* JavaScript typed arrays guide
* `DataView`
* `ArrayBuffer`
* `BigUint64Array`
DataView.prototype.getUint16()
==============================

The **`getUint16()`** method of `DataView` instances reads 2 bytes starting at the specified byte offset of this `DataView` and interprets them as a 16-bit unsigned integer. There is no alignment constraint; multi-byte values may be fetched from any offset within bounds.

Try it
------

Syntax
------


```js
getUint16(byteOffset)
getUint16(byteOffset, littleEndian)
```

### Parameters

`byteOffset`

The offset, in bytes, from the start of the view to read the data from.

`littleEndian` Optional

Indicates whether the data is stored in little- or big-endian format. If `false` or `undefined`, a big-endian value is read.

### Return value

An integer from 0 to 65535, inclusive.

### Exceptions

`RangeError`

Thrown if the `byteOffset` is set such that it would read beyond the end of the view.

Examples
--------

### Using getUint16()


```js
const { buffer } = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
const dataview = new DataView(buffer);
console.log(dataview.getUint16(1)); // 258
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-dataview.prototype.getuint16 |

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

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

See also
--------

* JavaScript typed arrays guide
* `DataView`
* `ArrayBuffer`
* `Uint16Array`
Symbol.species
==============

The **`Symbol.species`** static data property represents the well-known symbol `@@species`. Methods that create copies of an object may look up this symbol on the object for the constructor function to use when creating the copy.

**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.

Try it
------

Value
-----

The well-known symbol `@@species`.

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

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

The `@@species` accessor property allows subclasses to override the default constructor for objects. This specifies a protocol about how instances should be copied. For example, when you use copying methods of arrays, such as `map()`. the `map()` method uses `instance.constructor[Symbol.species]` to get the constructor for constructing the new array. For more information, see subclassing built-ins.

All built-in implementations of `@@species` return the `this` value, which is the current instance's constructor. This allows copying methods to create instances of derived classes rather than the base class — for example, `map()` will return an array of the same type as the original array.

Examples
--------

### Using species

You might want to return `Array` objects in your derived array class `MyArray`. For example, when using methods such as `map()` that return the default constructor, you want these methods to return a parent `Array` object, instead of the `MyArray` object. The `species` symbol lets you do this:


```js
class MyArray extends Array {
  // Overwrite species to the parent Array constructor
  static get [Symbol.species]() {
    return Array;
  }
}
const a = new MyArray(1, 2, 3);
const mapped = a.map((x) => x \* x);

console.log(mapped instanceof MyArray); // false
console.log(mapped instanceof Array); // true
```

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

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

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

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

See also
--------

* `Array[@@species]`
* `ArrayBuffer[@@species]`
* `Map[@@species]`
* `Promise[@@species]`
* `RegExp[@@species]`
* `Set[@@species]`
* `TypedArray[@@species]`
Symbol.prototype[@@toPrimitive]()
=================================

The **`[@@toPrimitive]()`** method of `Symbol` values returns this symbol value.

Syntax
------


```js
symbolValue[Symbol.toPrimitive](hint)
```

### Parameters

`hint`

A string value indicating the primitive value to return. The value is ignored.

### Return value

The primitive value of the specified `Symbol` object.

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

 The `[@@toPrimitive]()` method of `Symbol` returns the primitive
 value of a Symbol object as a Symbol data type. The `hint`
 argument is not used.

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

Examples
--------

### Using @@toPrimitive


```js
const sym = Symbol("example");
sym === sym[Symbol.toPrimitive](); // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-symbol.prototype-@@toprimitive |

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

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

See also
--------

* `Symbol.toPrimitive`
Symbol.asyncIterator
====================

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

Try it
------

Value
-----

The well-known symbol `@@asyncIterator`.

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

Examples
--------

### User-defined async iterables

You can define your own async iterable by setting the `[Symbol.asyncIterator]` property on an object.


```js
const myAsyncIterable = {
  async \*[Symbol.asyncIterator]() {
    yield "hello";
    yield "async";
    yield "iteration!";
  },
};

(async () => {
  for await (const x of myAsyncIterable) {
    console.log(x);
  }
})();
// Logs:
// "hello"
// "async"
// "iteration!"
```


When creating an API, remember that async iterables are designed to represent something *iterable* — like a stream of data or a list —, not to completely replace callbacks and events in most situations.

### Built-in async iterables

There is no object in the core JavaScript language that is async iterable. Some web APIs, such as `ReadableStream`, have the `Symbol.asyncIterator` method set by default.

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

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

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

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

See also
--------

* Iteration protocols
* for await...of
Symbol.prototype.description
============================

The **`description`** accessor property of `Symbol` values returns a string containing the description of this symbol, or `undefined` if the symbol has no description.

Try it
------

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

`Symbol` objects can be created with an optional description which can be used for debugging but not to access the symbol itself. The `Symbol.prototype.description` property can be used to read that description. It is different to `Symbol.prototype.toString()` as it does not contain the enclosing `"Symbol()"` string. See the examples.

Examples
--------

### Using description


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

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

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

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

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

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

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

See also
--------

* Polyfill of `Symbol.prototype.description` in `core-js`
* `Symbol.prototype.toString()`
Symbol.isConcatSpreadable
=========================

The **`Symbol.isConcatSpreadable`** static data property represents the well-known symbol `@@isConcatSpreadable`. The `Array.prototype.concat()` method looks up this symbol on each object being concatenated to determine if it should be treated as an array-like object and flattened to its array elements.

Try it
------

Value
-----

The well-known symbol `@@isConcatSpreadable`.

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

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

The `@@isConcatSpreadable` symbol (`Symbol.isConcatSpreadable`) can be defined as an own or inherited property and its value is a boolean. It can control behavior for arrays and array-like objects:

* For array objects, the default behavior is to spread (flatten) elements. `Symbol.isConcatSpreadable` can avoid flattening in these cases.
* For array-like objects, the default behavior is no spreading or flattening. `Symbol.isConcatSpreadable` can force flattening in these cases.
Examples
--------

### Arrays

By default, `Array.prototype.concat()` spreads (flattens) arrays into its result:


```js
const alpha = ["a", "b", "c"];
const numeric = [1, 2, 3];

const alphaNumeric = alpha.concat(numeric);

console.log(alphaNumeric); // Result: ['a', 'b', 'c', 1, 2, 3]
```


When setting `Symbol.isConcatSpreadable` to `false`, you can disable the default behavior:


```js
const alpha = ["a", "b", "c"];
const numeric = [1, 2, 3];

numeric[Symbol.isConcatSpreadable] = false;
const alphaNumeric = alpha.concat(numeric);

console.log(alphaNumeric); // Result: ['a', 'b', 'c', [1, 2, 3] ]
```

### Array-like objects

For array-like objects, the default is to not spread. `Symbol.isConcatSpreadable` needs to be set to `true` in order to get a flattened array:


```js
const x = [1, 2, 3];

const fakeArray = {
  [Symbol.isConcatSpreadable]: true,
  length: 2,
  0: "hello",
  1: "world",
};

x.concat(fakeArray); // [1, 2, 3, "hello", "world"]
```


**Note:** The `length` property is used to control the number of object properties to be added. In the above example, `length:2` indicates two properties has to be added.

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

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

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

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

See also
--------

* Polyfill of `Symbol.isConcatSpreadable` in `core-js`
* `Array.prototype.concat()`
Symbol.search
=============

The **`Symbol.search`** static data property represents the well-known symbol `@@search`. The `String.prototype.search()` method looks up this symbol on its first argument for the method that returns the index within a string that matches the current object.

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

Try it
------

Value
-----

The well-known symbol `@@search`.

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

Examples
--------

### Custom string search


```js
class caseInsensitiveSearch {
  constructor(value) {
    this.value = value.toLowerCase();
  }
  [Symbol.search](string) {
    return string.toLowerCase().indexOf(this.value);
  }
}

console.log("foobar".search(new caseInsensitiveSearch("BaR"))); // 3
```

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

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

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

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

See also
--------

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

The **`Symbol.split`** static data property represents the well-known symbol `@@split`. The `String.prototype.split()` method looks up this symbol on its first argument for the method that splits a string at the indices that match the current object.

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

Try it
------

Value
-----

The well-known symbol `@@split`.

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

Examples
--------

### Custom reverse split


```js
class ReverseSplit {
  [Symbol.split](string) {
    const array = string.split(" ");
    return array.reverse();
  }
}

console.log("Another one bites the dust".split(new ReverseSplit()));
// [ "dust", "the", "bites", "one", "Another" ]
```

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

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

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

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

See also
--------

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

 The **`Symbol.for()`** static method searches for existing symbols
 in a runtime-wide symbol registry with the given key and returns it if found. Otherwise
 a new symbol gets created in the global symbol registry with this key.

Try it
------

Syntax
------


```js
Symbol.for(key)
```

### Parameters

`key`

 String, required. The key for the symbol (and also used for the description of the
 symbol).


### Return value

 An existing symbol with the given key if found; otherwise, a new symbol is created and
 returned.

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

 In contrast to `Symbol()`, the `Symbol.for()` function creates a
 symbol available in a global symbol registry list. `Symbol.for()` does also
 not necessarily create a new symbol on every call, but checks first if a symbol with the
 given `key` is already present in the registry. In that case, that symbol is
 returned. If no symbol with the given key is found, `Symbol.for()` will
 create a new global symbol.

Examples
--------

### Using Symbol.for()


```js
Symbol.for("foo"); // create a new global symbol
Symbol.for("foo"); // retrieve the already created symbol

// Same global symbol, but not locally
Symbol.for("bar") === Symbol.for("bar"); // true
Symbol("bar") === Symbol("bar"); // false

// The key is also used as the description
const sym = Symbol.for("mario");
sym.toString(); // "Symbol(mario)"
```


 To avoid name clashes with your global symbol keys and other (library code) global
 symbols, it might be a good idea to prefix your symbols:


```js
Symbol.for("mdn.foo");
Symbol.for("mdn.bar");
```

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

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

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

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

See also
--------

* `Symbol.keyFor()`
Symbol.keyFor()
===============

 The **`Symbol.keyFor()`** static method retrieves a shared symbol
 key from the global symbol registry for the given symbol.

Try it
------

Syntax
------


```js
Symbol.keyFor(sym)
```

### Parameters

`sym`

Symbol, required. The symbol to find a key for.

### Return value

A string representing the key for the given symbol if one is found on the global registry; otherwise, `undefined`.

Examples
--------

### Using keyFor()


```js
const globalSym = Symbol.for("foo"); // create a new global symbol
Symbol.keyFor(globalSym); // "foo"

const localSym = Symbol();
Symbol.keyFor(localSym); // undefined

// well-known symbols are not symbols registered
// in the global symbol registry
Symbol.keyFor(Symbol.iterator); // undefined
```

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

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

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

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

See also
--------

* `Symbol.for()`
Symbol() constructor
====================

The **`Symbol()`** function returns primitive values of type Symbol.

Try it
------

Syntax
------


```js
Symbol()
Symbol(description)
```


**Note:** `Symbol()` can only be called without `new`. Attempting to construct it with `new` throws a `TypeError`.

### Parameters

`description` Optional

 A string. A description of the symbol which can be used for debugging but not to
 access the symbol itself.


Examples
--------

### Creating symbols

 To create a new primitive symbol, you write `Symbol()` with an optional
 string as its description:


```js
const sym1 = Symbol();
const sym2 = Symbol("foo");
const sym3 = Symbol("foo");
```


 The above code creates three new symbols. Note that `Symbol("foo")` does not
 coerce the string `"foo"` into a symbol. It creates a new symbol each time:


```js
Symbol("foo") === Symbol("foo"); // false
```

### new Symbol()

 The following syntax with the `new` operator will throw a
 `TypeError`:


```js
const sym = new Symbol(); // TypeError
```


 This prevents authors from creating an explicit `Symbol` wrapper object
 instead of a new symbol value and might be surprising as creating explicit wrapper
 objects around primitive data types is generally possible (for example,
 `new Boolean`, `new String` and `new Number`).

 If you really want to create a `Symbol` wrapper object, you can use the
 `Object()` function:


```js
const sym = Symbol("foo");
const symObj = Object(sym);
typeof sym; // "symbol"
typeof symObj; // "object"
```

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

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

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

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

See also
--------

* Polyfill of `Symbol` in `core-js`
Symbol.hasInstance
==================

The **`Symbol.hasInstance`** static data property represents the well-known symbol `@@hasInstance`. The `instanceof` operator looks up this symbol on its right-hand operand for the method used to determine if the constructor object recognizes an object as its instance.

Try it
------

Value
-----

The well-known symbol `@@hasInstance`.

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

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

The `instanceof` operator uses the following algorithm to calculate the return value of `object instanceof constructor`:

1. If `constructor` has a `@@hasInstance` method, then call it with `object` as the first argument and return the result, coerced to a boolean. Throw a `TypeError` if `constructor` is not an object, or if `constructor[@@hasInstance]` is not one of `null`, `undefined`, or a function.
2. Otherwise, if `constructor` doesn't have a `@@hasInstance` method (`constructor[@@hasInstance]` is `null` or `undefined`), then determine the result using the same algorithm as `Function.prototype[@@hasInstance]`. Throw a `TypeError` if `constructor` is not a function.

Because all functions inherit from `Function.prototype` by default, most of the time, the `Function.prototype[@@hasInstance]` method specifies the behavior of `instanceof` when the right-hand side is a function.

Examples
--------

### Custom instanceof behavior

You could implement your custom `instanceof` behavior like this, for example:


```js
class MyArray {
  static [Symbol.hasInstance](instance) {
    return Array.isArray(instance);
  }
}
console.log([] instanceof MyArray); // true
```



```js
function MyArray() {}
Object.defineProperty(MyArray, Symbol.hasInstance, {
  value(instance) {
    return Array.isArray(instance);
  },
});
console.log([] instanceof MyArray); // true
```

### Checking the instance of an object

Just in the same manner at which you can check if an object is an instance of a class using the `instanceof` keyword, we can also use `Symbol.hasInstance` for such checks.


```js
class Animal {
  constructor() {}
}

const cat = new Animal();

console.log(Animal[Symbol.hasInstance](cat)); // true
```

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

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

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

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

See also
--------

* `instanceof`
* `Function.prototype[@@hasInstance]()`