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

The **`slice()`** method of `TypedArray` instances returns a copy of a portion of a typed array into a new typed array object selected from `start` to `end` (`end` not included) where `start` and `end` represent the index of items in that typed array. The original typed array will not be modified. This method has the same algorithm as `Array.prototype.slice()`.

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.

`end` Optional

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

### Return value

A new typed array containing the extracted elements.

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

See `Array.prototype.slice()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Return a portion of an existing typed array


```js
const uint8 = new Uint8Array([1, 2, 3]);
uint8.slice(1); // Uint8Array [ 2, 3 ]
uint8.slice(2); // Uint8Array [ 3 ]
uint8.slice(-2); // Uint8Array [ 2, 3 ]
uint8.slice(0, 1); // Uint8Array [ 1 ]
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.slice |

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

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

See also
--------

* Polyfill of `TypedArray.prototype.slice` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `Array.prototype.slice()`
* `String.prototype.slice()`
TypedArray.prototype.toReversed()
=================================

The **`toReversed()`** method of `TypedArray` instances is the copying counterpart of the `reverse()` method. It returns a new typed array with the elements in reversed order. This method has the same algorithm as `Array.prototype.toReversed()`.

Syntax
------


```js
toReversed()
```

### Parameters

None.

### Return value

A new typed array containing the elements in reversed order.

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

See `Array.prototype.toReversed()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Using toReversed()


```js
const uint8 = new Uint8Array([1, 2, 3]);
const reversedUint8 = uint8.toReversed();
console.log(reversedUint8); // Uint8Array [3, 2, 1]
console.log(uint8); // Uint8Array [1, 2, 3]
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.toreversed |

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

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

See also
--------

* Polyfill of `TypedArray.prototype.toReversed` in `core-js`
* JavaScript typed arrays guide
* `TypedArray.prototype.reverse()`
* `TypedArray.prototype.toSorted()`
* `TypedArray.prototype.with()`
* `Array.prototype.toReversed()`
Error.prototype.toString()
==========================

The **`toString()`** method of `Error` instances returns a string representing this error.

Syntax
------


```js
toString()
```

### Parameters

None.

### Return value

A string representing the specified `Error` object.

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

 The `Error` object overrides the `Object.prototype.toString()`
 method inherited by all objects. Its semantics are as follows:


```js
Error.prototype.toString = function () {
  if (
    this === null ||
    (typeof this !== "object" && typeof this !== "function")
  ) {
    throw new TypeError();
  }
  let name = this.name;
  name = name === undefined ? "Error" : `${name}`;
  let msg = this.message;
  msg = msg === undefined ? "" : `${msg}`;
  if (name === "") {
    return msg;
  }
  if (msg === "") {
    return name;
  }
  return `${name}: ${msg}`;
};
```

Examples
--------

### Using toString()


```js
const e1 = new Error("fatal error");
console.log(e1.toString()); // "Error: fatal error"

const e2 = new Error("fatal error");
e2.name = undefined;
console.log(e2.toString()); // "Error: fatal error"

const e3 = new Error("fatal error");
e3.name = "";
console.log(e3.toString()); // "fatal error"

const e4 = new Error("fatal error");
e4.name = "";
e4.message = undefined;
console.log(e4.toString()); // ""

const e5 = new Error("fatal error");
e5.name = "hello";
e5.message = undefined;
console.log(e5.toString()); // "hello"
```

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

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

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

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

See also
--------

* Polyfill of `Error.prototype.toString` with many bug fixes in `core-js`
Error: lineNumber
=================

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The **`lineNumber`** data property of an `Error` instance contains the line number in the file that raised this error.

Value
-----

A positive integer.

| Property attributes of `Error: lineNumber` |
| --- |
| Writable | yes |
| Enumerable | no |
| Configurable | yes |

Examples
--------

### Using lineNumber


```js
try {
  throw new Error("Could not parse input");
} catch (err) {
  console.log(err.lineNumber); // 2
}
```

### Alternative example using error event


```js
window.addEventListener("error", (e) => {
  console.log(e.lineNumber); // 5
});
const e = new Error("Could not parse input");
throw e;
```


This is not a standard feature and lacks widespread support. See the browser compatibility table below.

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

Not part of any standard.

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

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

See also
--------

* `Error.prototype.stack`
* `Error.prototype.columnNumber`
* `Error.prototype.fileName`
Error.prototype.name
====================

The **`name`** data property of `Error.prototype` is shared by all `Error` instances. It represents the name for the type of error. For `Error.prototype.name`, the initial value is `"Error"`. Subclasses like `TypeError` and `SyntaxError` provide their own `name` properties.

Value
-----

A string. For `Error.prototype.name`, the initial value is `"Error"`.

| Property attributes of `Error.prototype.name` |
| --- |
| Writable | yes |
| Enumerable | no |
| Configurable | yes |

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

By default, `Error` instances are given the name "Error". The `name` property, in addition to the `message` property, is used by the `Error.prototype.toString()` method to create a string representation of the error.

Examples
--------

### Throwing a custom error


```js
const e = new Error("Malformed input"); // e.name is 'Error'

e.name = "ParseError";
throw e;
// e.toString() would return 'ParseError: Malformed input'
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-error.prototype.name |

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

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

See also
--------

* `Error.prototype.message`
* `Error.prototype.toString()`
Error: fileName
===============

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The **`fileName`** data property of an `Error` instance contains the path to the file that raised this error.

Value
-----

A string.

| Property attributes of `Error: fileName` |
| --- |
| Writable | yes |
| Enumerable | no |
| Configurable | yes |

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

This non-standard property contains the path to the file that raised this error. If called from a debugger context, the Firefox Developer Tools for example, "debugger eval code" is returned.

Examples
--------

### Using fileName


```js
const e = new Error("Could not parse input");
throw e;
// e.fileName could look like "file:///C:/example.html"
```

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

Not part of any standard.

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

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

See also
--------

* `Error.prototype.stack`
* `Error.prototype.columnNumber`
* `Error.prototype.lineNumber`
Error: message
==============

The **`message`** data property of an `Error` instance is a human-readable description of the error.

Value
-----

A string corresponding to the value passed to the `Error()` constructor as the first argument.

| Property attributes of `Error: message` |
| --- |
| Writable | yes |
| Enumerable | no |
| Configurable | yes |

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

This property contains a brief description of the error if one is available or has been set. The `message` property combined with the `name` property is used by the `Error.prototype.toString()` method to create a string representation of the Error.

By default, the `message` property is an empty string, but this behavior can be overridden for an instance by specifying a message as the first argument to the `Error` constructor.

Examples
--------

### Throwing a custom error


```js
const e = new Error("Could not parse input");
// e.message is 'Could not parse input'
throw e;
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-error.prototype.message |

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

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

See also
--------

* `Error.prototype.name`
* `Error.prototype.toString()`
Error: cause
============

The **`cause`** data property of an `Error` instance indicates the specific original cause of the error.

It is used when catching and re-throwing an error with a more-specific or useful error message in order to still have access to the original error.

Value
-----

The value that was passed to the `Error()` constructor in the `options.cause` argument. It may not be present.

| Property attributes of `Error: cause` |
| --- |
| Writable | yes |
| Enumerable | no |
| Configurable | yes |

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

The value of `cause` can be of any type. You should not make assumptions that the error you caught has an `Error` as its `cause`, in the same way that you cannot be sure the variable bound in the `catch` statement is an `Error` either. The "Providing structured data as the error cause" example below shows a case where a non-error is deliberately provided as the cause.

Examples
--------

### Rethrowing an error with a cause

 It is sometimes useful to catch an error and re-throw it with a new message.
 In this case you should pass the original error into the constructor for the new `Error`, as shown.


```js
try {
  connectToDatabase();
} catch (err) {
  throw new Error("Connecting to database failed.", { cause: err });
}
```


For a more detailed example see Error > Differentiate between similar errors.

### Providing structured data as the error cause

Error messages written for human consumption may be inappropriate for machine parsing — since they're subject to rewording or punctuation changes that may break any existing parsing written to consume them. So when throwing an error from a function, as an alternative to a human-readable error message, you can instead provide the cause as structured data, for machine parsing.


```js
function makeRSA(p, q) {
  if (!Number.isInteger(p) || !Number.isInteger(q)) {
    throw new Error("RSA key generation requires integer inputs.", {
      cause: { code: "NonInteger", values: [p, q] },
    });
  }
  if (!areCoprime(p, q)) {
    throw new Error("RSA key generation requires two co-prime integers.", {
      cause: { code: "NonCoprime", values: [p, q] },
    });
  }
  // rsa algorithm…
}
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-installerrorcause |

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

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

See also
--------

* `Error.prototype.message`
* `Error.prototype.toString()`
Error: columnNumber
===================

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The **`columnNumber`** data property of an `Error` instance contains the column number in the line of the file that raised this error.

Value
-----

A positive integer.

| Property attributes of `Error: columnNumber` |
| --- |
| Writable | yes |
| Enumerable | no |
| Configurable | yes |

Examples
--------

### Using columnNumber


```js
try {
  throw new Error("Could not parse input");
} catch (err) {
  console.log(err.columnNumber); // 9
}
```

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

Not part of any standard.

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

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

See also
--------

* `Error.prototype.stack`
* `Error.prototype.lineNumber`
* `Error.prototype.fileName`
Math.sign()
===========

The **`Math.sign()`** static method returns 1 or -1, indicating the sign of the number passed as argument. If the input is 0 or -0, it will be returned as-is.

Try it
------

Syntax
------


```js
Math.sign(x)
```

### Parameters

`x`

A number.

### Return value

A number representing the sign of `x`:

* If `x` is positive, returns `1`.
* If `x` is negative, returns `-1`.
* If `x` is positive zero, returns `0`.
* If `x` is negative zero, returns `-0`.
* Otherwise, returns `NaN`.
Description
-----------

Because `sign()` is a static method of `Math`, you always use it as `Math.sign()`, rather than as a method of a `Math` object you created (`Math` is not a constructor).

Examples
--------

### Using Math.sign()


```js
Math.sign(3); // 1
Math.sign(-3); // -1
Math.sign("-3"); // -1
Math.sign(0); // 0
Math.sign(-0); // -0
Math.sign(NaN); // NaN
Math.sign("foo"); // NaN
Math.sign(); // NaN
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-math.sign |

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

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

See also
--------

* Polyfill of `Math.sign` in `core-js`
* `Math.abs()`
* `Math.ceil()`
* `Math.floor()`
* `Math.round()`
* `Math.trunc()`
Math.LN2
========

The **`Math.LN2`** static data property represents the natural logarithm of 2, approximately 0.693:

Try it
------

Value
-----


𝙼𝚊𝚝𝚑.𝙻𝙽𝟸
=
ln
(
2
)
≈
0.693

\mathtt{\mi{Math.LN2}} = \ln(2) \approx 0.693



| Property attributes of `Math.LN2` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

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

Because `LN2` is a static property of `Math`, you always use it as `Math.LN2`, rather than as a property of a `Math` object you created (`Math` is not a constructor).

Examples
--------

### Using Math.LN2

The following function returns the natural log of 2:


```js
function getNatLog2() {
  return Math.LN2;
}

getNatLog2(); // 0.6931471805599453
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-math.ln2 |

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

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

See also
--------

* `Math.exp()`
* `Math.log()`
* `Math.log2()`
Math.expm1()
============

The **`Math.expm1()`** static method returns e raised to the power of a number, subtracted by 1. That is


𝙼𝚊𝚝𝚑.𝚎𝚡𝚙𝚖𝟷
(
𝚡
)

=

e
x

−
1

\mathtt{\operatorname{Math.expm1}(x)} = \mathrm{e}^x - 1

Try it
------

Syntax
------


```js
Math.expm1(x)
```

### Parameters

`x`

A number.

### Return value

A number representing ex - 1, where e is the base of the natural logarithm.

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

For very small values of *x*, adding 1 can reduce or eliminate precision. The double floats used in JS give you about 15 digits of precision. 1 + 1e-15 = 1.000000000000001, but 1 + 1e-16 = 1.000000000000000 and therefore exactly 1.0 in that arithmetic, because digits past 15 are rounded off.

When you calculate 


e
x

\mathrm{e}^x

 where x is a number very close to 0, you should get an answer very close to 1 + x, because 


lim

x
→
0


e
x

−
1

x

=
1

\lim\_{x \to 0} \frac{\mathrm{e}^x - 1}{x} = 1

. If you calculate `Math.exp(1.1111111111e-15) - 1`, you should get an answer close to `1.1111111111e-15`. Instead, due to the highest significant figure in the result of `Math.exp` being the units digit `1`, the final value ends up being `1.1102230246251565e-15`, with only 3 correct digits. If, instead, you calculate `Math.exp1m(1.1111111111e-15)`, you will get a much more accurate answer `1.1111111111000007e-15`, with 11 correct digits of precision.

Because `expm1()` is a static method of `Math`, you always use it as `Math.expm1()`, rather than as a method of a `Math` object you created (`Math` is not a constructor).

Examples
--------

### Using Math.expm1()


```js
Math.expm1(-Infinity); // -1
Math.expm1(-1); // -0.6321205588285577
Math.expm1(-0); // -0
Math.expm1(0); // 0
Math.expm1(1); // 1.718281828459045
Math.expm1(Infinity); // Infinity
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-math.expm1 |

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

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

See also
--------

* Polyfill of `Math.expm1` in `core-js`
* `Math.E`
* `Math.exp()`
* `Math.log()`
* `Math.log10()`
* `Math.log1p()`
* `Math.log2()`
* `Math.pow()`
Math.atanh()
============

The **`Math.atanh()`** static method returns the inverse hyperbolic tangent of a number. That is,



∀
x
∊
(

−
1

,
1
)
,

𝙼𝚊𝚝𝚑.𝚊𝚝𝚊𝚗𝚑
(
𝚡
)

=
artanh
(
x
)
=
the unique 
y
 such that 
tanh
(
y
)
=
x


=

1
2

ln

(

1
+
x

1
−
x

)

\begin{aligned}\forall x \in ({-1}, 1),;\mathtt{\operatorname{Math.atanh}(x)} &= \operatorname{artanh}(x) = \text{the unique } y \text{ such that } \tanh(y) = x \&= \frac{1}{2},\ln\left(\frac{1+x}{1-x}\right)\end{aligned}

Try it
------

Syntax
------


```js
Math.atanh(x)
```

### Parameters

`x`

A number between -1 and 1, inclusive.

### Return value

The inverse hyperbolic tangent of `x`. If `x` is 1, returns `Infinity`. If `x` is -1, returns `-Infinity`. If `x` is less than -1 or greater than 1, returns `NaN`.

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

Because `atanh()` is a static method of `Math`, you always use it as `Math.atanh()`, rather than as a method of a `Math` object you created (`Math` is not a constructor).

Examples
--------

### Using Math.atanh()


```js
Math.atanh(-2); // NaN
Math.atanh(-1); // -Infinity
Math.atanh(-0); // -0
Math.atanh(0); // 0
Math.atanh(0.5); // 0.5493061443340548
Math.atanh(1); // Infinity
Math.atanh(2); // NaN
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-math.atanh |

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

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

See also
--------

* Polyfill of `Math.atanh` in `core-js`
* `Math.acosh()`
* `Math.asinh()`
* `Math.cosh()`
* `Math.sinh()`
* `Math.tanh()`
Math.asinh()
============

The **`Math.asinh()`** static method returns the inverse hyperbolic sine of a number. That is,



𝙼𝚊𝚝𝚑.𝚊𝚜𝚒𝚗𝚑
(
𝚡
)

=
arsinh
(
x
)
=
the unique 
y
 such that 
sinh
(
y
)
=
x


=
ln

(

x
+

x
2

+
1

)

\begin{aligned}\mathtt{\operatorname{Math.asinh}(x)} &= \operatorname{arsinh}(x) = \text{the unique } y \text{ such that } \sinh(y) = x \&= \ln\left(x + \sqrt{x^2 + 1}\right)\end{aligned}

Try it
------

Syntax
------


```js
Math.asinh(x)
```

### Parameters

`x`

A number.

### Return value

The inverse hyperbolic sine of `x`.

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

Because `asinh()` is a static method of `Math`, you always use it as `Math.asinh()`, rather than as a method of a `Math` object you created (`Math` is not a constructor).

Examples
--------

### Using Math.asinh()


```js
Math.asinh(-Infinity); // -Infinity
Math.asinh(-1); // -0.881373587019543
Math.asinh(-0); // -0
Math.asinh(0); // 0
Math.asinh(1); // 0.881373587019543
Math.asinh(Infinity); // Infinity
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-math.asinh |

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

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

See also
--------

* Polyfill of `Math.asinh` in `core-js`
* `Math.acosh()`
* `Math.atanh()`
* `Math.cosh()`
* `Math.sinh()`
* `Math.tanh()`
Math.log1p()
============

The **`Math.log1p()`** static method returns the natural logarithm (base e) of `1 + x`, where `x` is the argument. That is:



∀
x
>
−
1
,

𝙼𝚊𝚝𝚑.𝚕𝚘𝚐𝟷𝚙
(
𝚡
)

=
ln
(
1
+
x
)

\forall x > -1,;\mathtt{\operatorname{Math.log1p}(x)} = \ln(1 + x)

Try it
------

Syntax
------


```js
Math.log1p(x)
```

### Parameters

`x`

A number greater than or equal to -1.

### Return value

The natural logarithm (base e) of `x + 1`. If `x` is -1, returns `-Infinity`. If `x < -1`, returns `NaN`.

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

For very small values of *x*, adding 1 can reduce or eliminate precision. The double floats used in JS give you about 15 digits of precision. 1 + 1e-15 = 1.000000000000001, but 1 + 1e-16 = 1.000000000000000 and therefore exactly 1.0 in that arithmetic, because digits past 15 are rounded off.

When you calculate log(1 + *x*) where *x* is a small positive number, you should get an answer very close to *x*, because 


lim

x
→
0

log
⁡
(
1
+
x
)

x

=
1

\lim\_{x \to 0} \frac{\log(1+x)}{x} = 1

. If you calculate `Math.log(1 + 1.1111111111e-15)`, you should get an answer close to `1.1111111111e-15`. Instead, you will end up taking the logarithm of `1.00000000000000111022` (the roundoff is in binary, so sometimes it gets ugly), and get the answer 1.11022…e-15, with only 3 correct digits. If, instead, you calculate `Math.log1p(1.1111111111e-15)`, you will get a much more accurate answer `1.1111111110999995e-15`, with 15 correct digits of precision (actually 16 in this case).

If the value of `x` is less than -1, the return value is always `NaN`.

Because `log1p()` is a static method of `Math`, you always use it as `Math.log1p()`, rather than as a method of a `Math` object you created (`Math` is not a constructor).

Examples
--------

### Using Math.log1p()


```js
Math.log1p(-2); // NaN
Math.log1p(-1); // -Infinity
Math.log1p(-0); // -0
Math.log1p(0); // 0
Math.log1p(1); // 0.6931471805599453
Math.log1p(Infinity); // Infinity
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-math.log1p |

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

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

See also
--------

* Polyfill of `Math.log1p` in `core-js`
* `Math.exp()`
* `Math.log()`
* `Math.expm1()`
* `Math.log10()`
* `Math.log2()`
* `Math.pow()`