recursal/MDN huggingface dataset:
ArrayBuffer.prototype.slice()
=============================

The **`slice()`** method of `ArrayBuffer` instances returns a new `ArrayBuffer` whose contents are a copy of this `ArrayBuffer`'s bytes from `start`, inclusive, up to `end`, exclusive. If either `start` or `end` is negative, it refers to an index from the end of the array, as opposed to from the beginning.

Try it
------

Syntax
------


```js
slice()
slice(start)
slice(start, end)
```

### Parameters

`start` Optional

Zero-based index at which to start extraction, converted to an integer.

* Negative index counts back from the end of the buffer — if `start < 0`, `start + buffer.length` is used.
* If `start < -buffer.length` or `start` is omitted, `0` is used.
* If `start >= buffer.length`, nothing is extracted.

`end` Optional

Zero-based index at which to end extraction, converted to an integer. `slice()` extracts up to but not including `end`.

* Negative index counts back from the end of the buffer — if `end < 0`, `end + buffer.length` is used.
* If `end < -buffer.length`, `0` is used.
* If `end >= buffer.length` or `end` is omitted, `buffer.length` is used, causing all elements until the end to be extracted.
* If `end` is positioned before or at `start` after normalization, nothing is extracted.

### Return value

A new `ArrayBuffer` containing the extracted elements.

Examples
--------

### Copying an ArrayBuffer


```js
const buf1 = new ArrayBuffer(8);
const buf2 = buf1.slice(0);
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-arraybuffer.prototype.slice |

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

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

See also
--------

* `ArrayBuffer`
* `SharedArrayBuffer.prototype.slice()`
ArrayBuffer.prototype.detached
==============================

The **`detached`** accessor property of `ArrayBuffer` instances returns a boolean indicating whether or not this buffer has been detached (transferred).

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

The `detached` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is `false` when the `ArrayBuffer` is first created. The value becomes `true` if the `ArrayBuffer` is transferred, which detaches the instance from its underlying memory. Once a buffer becomes detached, it is no longer usable.

Examples
--------

### Using detached


```js
const buffer = new ArrayBuffer(8);
console.log(buffer.detached); // false
const newBuffer = buffer.transfer();
console.log(buffer.detached); // true
console.log(newBuffer.detached); // false
```

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

| Specification |
| --- |
| ArrayBuffer transfer # sec-get-arraybuffer.prototype.detached |

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

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

See also
--------

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

The **`resize()`** method of `ArrayBuffer` instances resizes the `ArrayBuffer` to the specified size, in bytes.

Try it
------

Syntax
------


```js
resize(newLength)
```

### Parameters

`newLength`

The new length, in bytes, to resize the `ArrayBuffer` to.

### Return value

None (`undefined`).

### Exceptions

`TypeError`

Thrown if the `ArrayBuffer` is detached or is not resizable.

`RangeError`

Thrown if `newLength` is larger than the `maxByteLength` of the `ArrayBuffer`.

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

The `resize()` method resizes an `ArrayBuffer` to the size specified by the `newLength` parameter, provided that the `ArrayBuffer` is resizable and the new size is less than or equal to the `maxByteLength` of the `ArrayBuffer`. New bytes are initialized to 0.

Note that you can use `resize()` to shrink as well as grow an `ArrayBuffer` — it is permissible for `newLength` to be smaller than the `ArrayBuffer`'s current `byteLength`.

Examples
--------

### Using resize()

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-arraybuffer.prototype.resize |

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

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

See also
--------

* `ArrayBuffer`
* `ArrayBuffer.prototype.resizable`
* `ArrayBuffer.prototype.maxByteLength`
ArrayBuffer() constructor
=========================

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

Try it
------

Syntax
------


```js
new ArrayBuffer(length)
new ArrayBuffer(length, options)
```


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

### Parameters

`length`

The size, in bytes, of the array buffer to create.

`options` Optional

An object, which can contain the following properties:

`maxByteLength` Optional

The maximum size, in bytes, that the array buffer can be resized to.


### Return value

A new `ArrayBuffer` object of the specified size, with its `maxByteLength` property set to the specified `maxByteLength` if one was specified. Its contents are initialized to 0.

### Exceptions

`RangeError`

Thrown in one of the following cases:

* `length` or `maxByteLength` is larger than `Number.MAX_SAFE_INTEGER` (≥ 253) or negative.
* `length` is larger than `maxByteLength`.

Examples
--------

### Creating an ArrayBuffer

In this example, we create a 8-byte buffer with a `Int32Array` view referring to the buffer:


```js
const buffer = new ArrayBuffer(8);
const view = new Int32Array(buffer);
```

### Creating a resizable ArrayBuffer

In this example, we create a 8-byte buffer that is resizable to a max length of 16 bytes, then `resize()` it to 12 bytes:


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

buffer.resize(12);
```


**Note:** It is recommended that `maxByteLength` is set to the smallest value possible for your use case. It should never exceed `1073741824` (1GB) to reduce the risk of out-of-memory errors.

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

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

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

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

See also
--------

* Polyfill of `ArrayBuffer` in `core-js`
* JavaScript typed arrays guide
* `SharedArrayBuffer`
Function.prototype[@@hasInstance]()
===================================

The **`[@@hasInstance]()`** method of `Function` instances specifies the default procedure for determining if a constructor function recognizes an object as one of the constructor's instances. It is called by the `instanceof` operator.

Syntax
------


```js
func[Symbol.hasInstance](value)
```

### Parameters

`value`

The object to test. Primitive values always return `false`.

### Return value

`true` if `func.prototype` is in the prototype chain of `value`; otherwise, `false`. Always returns `false` if `value` is not an object or `this` is not a function. If `this` is a bound function, returns the result of a `instanceof` test on `value` and the underlying target function.

### Exceptions

`TypeError`

Thrown if `this` is not a bound function and `this.prototype` is not an object.

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

The `instanceof` operator calls the `[@@hasInstance]()` method of the right-hand side whenever such a method exists. Because all functions inherit from `Function.prototype` by default, they would all have the `[@@hasInstance]()` method, so most of the time, the `Function.prototype[@@hasInstance]` method specifies the behavior of `instanceof` when the right-hand side is a function. This method implements the default behavior of the `instanceof` operator (the same algorithm when `constructor` has no `@@hasInstance` method).

Unlike most methods, the `Function.prototype[@@hasInstance]()` property is non-configurable and non-writable. This is a security feature to prevent the underlying target function of a bound function from being obtainable. See this StackOverflow answer for an example.

Examples
--------

### Reverting to default instanceof behavior

You would rarely need to call this method directly. Instead, this method is called by the `instanceof` operator. You should expect the two results to usually be equivalent.


```js
class Foo {}
const foo = new Foo();
console.log(foo instanceof Foo === Foo[Symbol.hasInstance](foo)); // true
```


You may want to use this method if you want to invoke the default `instanceof` behavior, but you don't know if a constructor has a overridden `[@@hasInstance]()` method.


```js
class Foo {
  static [Symbol.hasInstance](value) {
    // A custom implementation
    return false;
  }
}

const foo = new Foo();
console.log(foo instanceof Foo); // false
console.log(Function.prototype[Symbol.hasInstance].call(Foo, foo)); // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-function.prototype-@@hasinstance |

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

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

See also
--------

* `instanceof`
* `Symbol.hasInstance`
Function: length
================

The **`length`** data property of a `Function` instance indicates the number of parameters expected by the function.

Try it
------

Value
-----

A number.

| Property attributes of `Function: length` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | yes |

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

A `Function` object's `length` property indicates how many arguments the function expects, i.e. the number of formal parameters. This number excludes the rest parameter and only includes parameters before the first one with a default value. By contrast, `arguments.length` is local to a function and provides the number of arguments actually passed to the function.

The `Function` constructor is itself a `Function` object. Its `length` data property has a value of `1`.

Due to historical reasons, `Function.prototype` is a callable itself. The `length` property of `Function.prototype` has a value of `0`.

Examples
--------

### Using function length


```js
console.log(Function.length); // 1

console.log((() => {}).length); // 0
console.log(((a) => {}).length); // 1
console.log(((a, b) => {}).length); // 2 etc.

console.log(((...args) => {}).length);
// 0, rest parameter is not counted

console.log(((a, b = 1, c) => {}).length);
// 1, only parameters before the first one with
// a default value are counted
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-function-instances-length |

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

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

See also
--------

* `Function`
Set.prototype.clear()
=====================

The **`clear()`** method of `Set` instances removes all elements from this set.

Try it
------

Syntax
------


```js
clear()
```

### Parameters

None.

### Return value

None (`undefined`).

Examples
--------

### Using the clear() method


```js
const mySet = new Set();
mySet.add(1);
mySet.add("foo");

console.log(mySet.size); // 2
console.log(mySet.has("foo")); // true

mySet.clear();

console.log(mySet.size); // 0
console.log(mySet.has("foo")); // false
```

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

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

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

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

See also
--------

* `Set`
* `Set.prototype.delete()`
Set.prototype.delete()
======================

The **`delete()`** method of `Set` instances removes a specified value from this set, if it is in the set.

Try it
------

Syntax
------


```js
setInstance.delete(value)
```

### Parameters

`value`

The value to remove from `Set`.

### Return value

 Returns `true` if `value` was already in
 `Set`; otherwise `false`.

Examples
--------

### Using the delete() method


```js
const mySet = new Set();
mySet.add("foo");

console.log(mySet.delete("bar")); // false; no "bar" element found to be deleted.
console.log(mySet.delete("foo")); // true; successfully removed.

console.log(mySet.has("foo")); // false; the "foo" element is no longer present.
```

### Deleting an object from a set

Because objects are compared by reference, you have to delete them by checking individual properties if you don't have a reference to the original object.


```js
const setObj = new Set(); // Create a new set.

setObj.add({ x: 10, y: 20 }); // Add object in the set.

setObj.add({ x: 20, y: 30 }); // Add object in the set.

// Delete any point with `x > 10`.
setObj.forEach((point) => {
  if (point.x > 10) {
    setObj.delete(point);
  }
});
```

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

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

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

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

See also
--------

* `Set`
* `Set.prototype.clear()`
Set.prototype.union()
=====================

Limited availability
--------------------

This feature is not Baseline because it does not work in some of the most widely-used browsers.

* Learn more
* See full compatibility
* Report feedback
**Experimental:** **This is an experimental technology**  
Check the Browser compatibility table carefully before using this in production.

The **`union()`** method of `Set` instances takes a set and returns a new set containing elements which are in either or both of this set and the given set.

Syntax
------


```js
union(other)
```

### Parameters

`other`

A `Set` object, or set-like object.

### Return value

A new `Set` object containing elements which are in either or both of this set and the `other` set.

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

In mathematical notation, *union* is defined as:



A
∪
B
=
{
x
∣
x
∊
A
 or 
x
∊
B
}

A\cup B = {x\midx\in A\text{ or }x\in B}


And using Venn diagram:

![A Venn diagram where two circles overlap. The symmetric difference of A and B is the region contained by either or both circles.](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union/diagram.svg)

`union()` accepts set-like objects as the `other` parameter. It requires `this` to be an actual `Set` instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this`, followed by all elements in `other` that are not present in `this`.

The order of elements in the returned set is first those in `this` followed by those in `other`.

Examples
--------

### Using union()

The following example computes the union between the set of even numbers (<10) and the set of perfect squares (<10). The result is the set of numbers that are either even or a perfect square, or both.


```js
const evens = new Set([2, 4, 6, 8]);
const squares = new Set([1, 4, 9]);
console.log(evens.union(squares)); // Set(6) { 1, 2, 4, 6, 8, 9 }
```

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

| Specification |
| --- |
| Set methods # sec-set.prototype.union |

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

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

See also
--------

* Polyfill of `Set.prototype.union` in `core-js`
* `Set.prototype.difference()`
* `Set.prototype.intersection()`
* `Set.prototype.isDisjointFrom()`
* `Set.prototype.isSubsetOf()`
* `Set.prototype.isSupersetOf()`
* `Set.prototype.symmetricDifference()`
Set[@@species]
==============

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

Syntax
------


```js
Set[Symbol.species]
```

### Return value

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

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

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

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

Examples
--------

### Species in ordinary objects

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


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

### Species in derived objects

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


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

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

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

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

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

See also
--------

* `Set`
* `Symbol.species`
Set.prototype.intersection()
============================

Limited availability
--------------------

This feature is not Baseline because it does not work in some of the most widely-used browsers.

* Learn more
* See full compatibility
* Report feedback
**Experimental:** **This is an experimental technology**  
Check the Browser compatibility table carefully before using this in production.

The **`intersection()`** method of `Set` instances takes a set and returns a new set containing elements in both this set and the given set.

Syntax
------


```js
intersection(other)
```

### Parameters

`other`

A `Set` object, or set-like object.

### Return value

A new `Set` object containing elements in both this set and the `other` set.

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

In mathematical notation, *intersection* is defined as:



A
∩
B
=
{
x
∊
A
∣
x
∊
B
}

A\cap B = {x\in A\mid x\in B}


And using Venn diagram:

![A Venn diagram where two circles overlap. The intersection of A and B is the part where they overlap.](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection/diagram.svg)

`intersection()` accepts set-like objects as the `other` parameter. It requires `this` to be an actual `Set` instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`:

* If there are more elements in `this` than `other.size`, then it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements produced that are also present in `this`.
* Otherwise, it iterates over the elements in `this`, and constructs a new set with all elements `e` in `this` that cause `other.has(e)` to return a truthy value.

Because of this implementation, the efficiency of `intersection()` mostly depends on the size of the smaller set between `this` and `other` (assuming sets can be accessed in sublinear time). The order of elements in the returned set is the same as that of the smaller of `this` and `other`.

Examples
--------

### Using intersection()

The following example computes the intersection between the set of odd numbers (<10) and the set of perfect squares (<10). The result is the set of odd numbers that are perfect squares.


```js
const odds = new Set([1, 3, 5, 7, 9]);
const squares = new Set([1, 4, 9]);
console.log(odds.intersection(squares)); // Set(2) { 1, 9 }
```

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

| Specification |
| --- |
| Set methods # sec-set.prototype.intersection |

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

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

See also
--------

* Polyfill of `Set.prototype.intersection` in `core-js`
* `Set.prototype.difference()`
* `Set.prototype.isDisjointFrom()`
* `Set.prototype.isSubsetOf()`
* `Set.prototype.isSupersetOf()`
* `Set.prototype.symmetricDifference()`
* `Set.prototype.union()`
Set.prototype.symmetricDifference()
===================================

Limited availability
--------------------

This feature is not Baseline because it does not work in some of the most widely-used browsers.

* Learn more
* See full compatibility
* Report feedback
**Experimental:** **This is an experimental technology**  
Check the Browser compatibility table carefully before using this in production.

The **`symmetricDifference()`** method of `Set` instances takes a set and returns a new set containing elements which are in either this set or the given set, but not in both.

Syntax
------


```js
symmetricDifference(other)
```

### Parameters

`other`

A `Set` object, or set-like object.

### Return value

A new `Set` object containing elements which are in either this set or the `other` set, but not in both.

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

In mathematical notation, *symmetric difference* is defined as:



A
⊖
B
=
(
A
∖
B
)
∪
(
B
∖
A
)

A\ominus B = (A\setminus B)\cup(B\setminus A)


And using Venn diagram:

![A Venn diagram where two circles overlap. The symmetric difference of A and B is the region contained by either circle but not both.](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference/diagram.svg)

`symmetricDifference()` accepts set-like objects as the `other` parameter. It requires `this` to be an actual `Set` instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this` that are not seen in `other`, and all elements in `other` that are not seen in `this`.

The order of elements in the returned set is first those in `this` followed by those in `other`.

Examples
--------

### Using symmetricDifference()

The following example computes the symmetric difference between the set of even numbers (<10) and the set of perfect squares (<10). The result is the set of numbers that are either even or a perfect square, but not both.


```js
const evens = new Set([2, 4, 6, 8]);
const squares = new Set([1, 4, 9]);
console.log(evens.symmetricDifference(squares)); // Set(5) { 1, 2, 6, 8, 9 }
```

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

| Specification |
| --- |
| Set methods # sec-set.prototype.symmetricDifference |

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

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

See also
--------

* Polyfill of `Set.prototype.symmetricDifference` in `core-js`
* `Set.prototype.difference()`
* `Set.prototype.intersection()`
* `Set.prototype.isDisjointFrom()`
* `Set.prototype.isSubsetOf()`
* `Set.prototype.isSupersetOf()`
* `Set.prototype.union()`