recursal/MDN huggingface dataset:
Number.isInteger()
==================

The **`Number.isInteger()`** static method determines whether the passed value is an integer.

Try it
------

Syntax
------


```js
Number.isInteger(value)
```

### Parameters

`value`

The value to be tested for being an integer.

### Return value

The boolean value `true` if the given value is an integer. Otherwise `false`.

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

If the target value is an integer, return `true`, otherwise return `false`. If the value is `NaN` or `Infinity`, return `false`. The method will also return `true` for floating point numbers that can be represented as integer. It will always return `false` if the value is not a number.

Note that some number literals, while looking like non-integers, actually represent integers — due to the precision limit of ECMAScript floating-point number encoding (IEEE-754). For example, `5.0000000000000001` only differs from `5` by `1e-16`, which is too small to be represented. (For reference, `Number.EPSILON` stores the distance between 1 and the next representable floating-point number greater than 1, and that is about `2.22e-16`.) Therefore, `5.0000000000000001` will be represented with the same encoding as `5`, thus making `Number.isInteger(5.0000000000000001)` return `true`.

In a similar sense, numbers around the magnitude of `Number.MAX_SAFE_INTEGER` will suffer from loss of precision and make `Number.isInteger` return `true` even when it's not an integer. (The actual threshold varies based on how many bits are needed to represent the decimal — for example, `Number.isInteger(4500000000000000.1)` is `true`, but `Number.isInteger(4500000000000000.5)` is `false`.)

Examples
--------

### Using isInteger


```js
Number.isInteger(0); // true
Number.isInteger(1); // true
Number.isInteger(-100000); // true
Number.isInteger(99999999999999999999999); // true

Number.isInteger(0.1); // false
Number.isInteger(Math.PI); // false

Number.isInteger(NaN); // false
Number.isInteger(Infinity); // false
Number.isInteger(-Infinity); // false
Number.isInteger("10"); // false
Number.isInteger(true); // false
Number.isInteger(false); // false
Number.isInteger([1]); // false

Number.isInteger(5.0); // true
Number.isInteger(5.000000000000001); // false
Number.isInteger(5.0000000000000001); // true, because of loss of precision
Number.isInteger(4500000000000000.1); // true, because of loss of precision
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-number.isinteger |

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

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

See also
--------

* Polyfill of `Number.isInteger` in `core-js`
* `Number`
Number.MAX\_SAFE\_INTEGER
=========================

The **`Number.MAX_SAFE_INTEGER`** static data property represents the maximum safe integer in JavaScript (253 – 1).

For larger integers, consider using `BigInt`.

Try it
------

Value
-----

`9007199254740991` (9,007,199,254,740,991, or ~9 quadrillion).

| Property attributes of `Number.MAX_SAFE_INTEGER` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

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

Double precision floating point format only has 52 bits to represent the mantissa, so it can only safely represent integers between -(253 – 1) and 253 – 1. "Safe" in this context refers to the ability to represent integers exactly and to compare them correctly. For example, `Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2` will evaluate to true, which is mathematically incorrect. See `Number.isSafeInteger()` for more information.

Because `MAX_SAFE_INTEGER` is a static property of `Number`, you always use it as `Number.MAX_SAFE_INTEGER`, rather than as a property of a number value.

Examples
--------

### Return value of MAX\_SAFE\_INTEGER


```js
Number.MAX\_SAFE\_INTEGER; // 9007199254740991
```

### Relationship between MAX\_SAFE\_INTEGER and EPSILON

`Number.EPSILON` is 2-52, while `MAX_SAFE_INTEGER` is 253 – 1 — both of them are derived from the width of the mantissa, which is 53 bits (with the highest bit always being 1). Multiplying them will give a value very close — but not equal — to 2.


```js
Number.MAX\_SAFE\_INTEGER \* Number.EPSILON; // 1.9999999999999998
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-number.max\_safe\_integer |

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

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

See also
--------

* Polyfill of `Number.MAX_SAFE_INTEGER` in `core-js`
* `Number.MIN_SAFE_INTEGER`
* `Number.isSafeInteger()`
* `BigInt`
Number.prototype.valueOf()
==========================

The **`valueOf()`** method of `Number` values returns the value of this number.

Try it
------

Syntax
------


```js
valueOf()
```

### Parameters

None.

### Return value

A number representing the primitive value of the specified `Number` object.

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

This method is usually called internally by JavaScript and not explicitly in web code.

Examples
--------

### Using valueOf


```js
const numObj = new Number(10);
console.log(typeof numObj); // object

const num = numObj.valueOf();
console.log(num); // 10
console.log(typeof num); // number
```

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

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

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

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

See also
--------

* `Object.prototype.valueOf()`
Number.MAX\_VALUE
=================

The **`Number.MAX_VALUE`** static data property represents the maximum numeric value representable in JavaScript.

Try it
------

Value
-----

21024 - 2971, or approximately `1.7976931348623157E+308`.

| Property attributes of `Number.MAX_VALUE` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

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

Values larger than `MAX_VALUE` are represented as `Infinity` and will lose their actual value.

Because `MAX_VALUE` is a static property of `Number`, you always use it as `Number.MAX_VALUE`, rather than as a property of a number value.

Examples
--------

### Using MAX\_VALUE

The following code multiplies two numeric values. If the result is less than or equal to `MAX_VALUE`, the `func1` function is called; otherwise, the `func2` function is called.


```js
if (num1 \* num2 <= Number.MAX\_VALUE) {
  func1();
} else {
  func2();
}
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-number.max\_value |

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

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

See also
--------

* `Number.MIN_VALUE`
* `Number`
Number.isSafeInteger()
======================

The **`Number.isSafeInteger()`** static method determines whether the provided value is a number that is a *safe integer*.

Try it
------

Syntax
------


```js
Number.isSafeInteger(testValue)
```

### Parameters

`testValue`

The value to be tested for being a safe integer.

### Return value

The boolean value `true` if the given value is a number that is a safe integer. Otherwise `false`.

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

The safe integers consist of all integers from -(253 - 1) to 253 - 1, inclusive (±9,007,199,254,740,991). A safe integer is an integer that:

* can be exactly represented as an IEEE-754 double precision number, and
* whose IEEE-754 representation cannot be the result of rounding any other integer to fit the IEEE-754 representation.

For example, 253 - 1 is a safe integer: it can be exactly represented, and no other integer rounds to it under any IEEE-754 rounding mode. In contrast, 253 is *not* a safe integer: it can be exactly represented in IEEE-754, but the integer 253 + 1 can't be directly represented in IEEE-754 but instead rounds to 253 under round-to-nearest and round-to-zero rounding.

Handling values larger or smaller than ~9 quadrillion with full precision requires using an arbitrary precision arithmetic library. See What Every Programmer Needs to Know about Floating Point Arithmetic for more information on floating point representations of numbers.

For larger integers, consider using the `BigInt` type.

Examples
--------

### Using isSafeInteger()


```js
Number.isSafeInteger(3); // true
Number.isSafeInteger(2 \*\* 53); // false
Number.isSafeInteger(2 \*\* 53 - 1); // true
Number.isSafeInteger(NaN); // false
Number.isSafeInteger(Infinity); // false
Number.isSafeInteger("3"); // false
Number.isSafeInteger(3.1); // false
Number.isSafeInteger(3.0); // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-number.issafeinteger |

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

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

See also
--------

* Polyfill of `Number.isSafeInteger` in `core-js`
* `Number`
* `Number.MIN_SAFE_INTEGER`
* `Number.MAX_SAFE_INTEGER`
* `BigInt`
Number.parseInt()
=================

 The **`Number.parseInt()`** static method parses a string argument and
 returns an integer of the specified radix or base.

Try it
------

Syntax
------


```js
Number.parseInt(string)
Number.parseInt(string, radix)
```

### Parameters

`string`

The value to parse, coerced to a string. Leading whitespace in this argument is ignored.

`radix` Optional

 An integer between `2` and `36` that represents the
 *radix* (the base in mathematical numeral systems) of the
 `string`.


If `radix` is undefined or `0`, it is assumed to be `10` except when the number begins with the code unit pairs `0x` or `0X`, in which case a radix of `16` is assumed.

### Return value

An integer parsed from the given `string`.

 If the `radix` is smaller than `2` or bigger than
 `36`, or the first non-whitespace character cannot be converted to a number,
 `NaN` is returned.

Examples
--------

### Number.parseInt vs. parseInt

This method has the same functionality as the global `parseInt()` function:


```js
Number.parseInt === parseInt; // true
```


 Its purpose is modularization of globals. Please see
 `parseInt()` for more detail and examples.

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-number.parseint |

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

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

See also
--------

* Polyfill of `Number.parseInt` in `core-js`
* `Number`
* `parseInt()`
AggregateError() constructor
============================

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

Syntax
------


```js
new AggregateError(errors)
new AggregateError(errors, message)
new AggregateError(errors, message, options)

AggregateError(errors)
AggregateError(errors, message)
AggregateError(errors, message, options)
```


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

### Parameters

`errors`

An iterable of errors, may not actually be `Error` instances.

`message` Optional

An optional human-readable description of the aggregate error.

`options` Optional

An object that has the following properties:

`cause` Optional

 A property indicating the specific cause of the error.
 When catching and re-throwing an error with a more-specific or useful error message, this property can be used to pass the original error.



Examples
--------

### Creating an AggregateError


```js
try {
  throw new AggregateError([new Error("some error")], "Hello");
} catch (e) {
  console.log(e instanceof AggregateError); // true
  console.log(e.message); // "Hello"
  console.log(e.name); // "AggregateError"
  console.log(e.errors); // [ Error: "some error" ]
}
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-aggregate-error-constructor |

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

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

See also
--------

* Polyfill of `AggregateError` in `core-js`
* `Promise.any`
AggregateError: errors
======================

The **`errors`** data property of an `AggregateError` instance contains an array representing the errors that were aggregated.

Value
-----

An `Array` containing values in the same order as the iterable passed as the first argument of the `AggregateError()` constructor.

| Property attributes of `AggregateError: errors` |
| --- |
| Writable | yes |
| Enumerable | no |
| Configurable | yes |

Examples
--------

### Using errors


```js
try {
  throw new AggregateError(
    // An iterable of errors
    new Set([new Error("some error"), new Error("another error")]),
    "Multiple errors thrown",
  );
} catch (err) {
  console.log(err.errors);
  // [
  // Error: some error,
  // Error: another error
  // ]
}
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-aggregate-error |

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

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

See also
--------

* Control flow and error handling guide
* `AggregateError`
* `Error`: `cause`
AsyncGenerator.prototype.next()
===============================

The **`next()`** method of `AsyncGenerator` instances returns the next value in the sequence.

Syntax
------


```js
next()
next(value)
```

### Parameters

`value` Optional

An optional value used to modify the internal state of the generator. A value passed to the `next()` method will be received by `yield`

### Return value

A `Promise` which when resolved returns an `Object` with two properties:

`done`

A boolean value:

* `true` if the generator is past the end of its control flow. In this case `value` specifies the *return value* of the generator (which may be undefined).
* `false` if the generator is able to produce more values.

`value`

Any JavaScript value yielded or returned by the generator.

Examples
--------

### Using next()

The following example shows a simple generator and the object that the `next` method returns:


```js
// An async task. Pretend it's doing something more useful
// in practice.
function delayedValue(time, value) {
  return new Promise((resolve, reject) => {
    setTimeout(() => resolve(value), time);
  });
}

async function\* createAsyncGenerator() {
  yield delayedValue(500, 1);
  yield delayedValue(500, 2);
  yield delayedValue(500, 3);
}

const asyncGen = createAsyncGenerator();
asyncGen.next().then((res) => console.log(res)); // { value: 1, done: false }
asyncGen.next().then((res) => console.log(res)); // { value: 2, done: false }
asyncGen.next().then((res) => console.log(res)); // { value: 3, done: false }
asyncGen.next().then((res) => console.log(res)); // { value: undefined, done: true }
```

### Sending values to the generator

In this example, `next` is called with a value.

**Note:** The first call does not log anything, because the generator was not yielding anything initially.


```js
// An async task. Pretend it's doing something more useful
// in practice.
function sleep(time) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, time);
  });
}

async function\* createAsyncGenerator() {
  while (true) {
    await sleep(500);
    const value = yield;
    console.log(value);
  }
}

async function main() {
  const asyncGen = createAsyncGenerator();
  // No log at this step: the first value sent through `next` is lost
  console.log(await asyncGen.next(1)); // { value: undefined, done: false }
  // Logs 2: the value sent through `next`
  console.log(await asyncGen.next(2)); // { value: undefined, done: false }
}

main();
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-asyncgenerator-prototype-next |

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

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

See also
--------

* `async function*`
* Iterators and generators guide
AsyncGenerator.prototype.throw()
================================

The **`throw()`** method of `AsyncGenerator` instances acts as if a `throw` statement is inserted in the generator's body at the current suspended position, which informs the generator of an error condition and allows it to handle the error, or perform cleanup and close itself.

Syntax
------


```js
asyncGeneratorInstance.throw(exception)
```

### Parameters

`exception`

The exception to throw. For debugging purposes, it is useful to make it an `instanceof` `Error`.

### Return value

If the thrown error is not caught, it will return a `Promise` which rejects with the exception passed in.

If the exception is caught by a `try...catch` and the generator resumes to yield more values, it will return a `Promise` which resolves with an `Object` with two properties:

`done`

A boolean value:

* `true` if the generator function's control flow has reached the end.
* `false` if the generator function is able to produce more values.

`value`

The value yielded from the next `yield` expression.

Examples
--------

### Using throw()

The following example shows a simple generator and an error that is thrown using the `throw` method. An error can be caught by a `try...catch` block as usual.


```js
// An async task. Pretend it's doing something more useful
// in practice.
function sleep(time) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, time);
  });
}

async function\* createAsyncGenerator() {
  while (true) {
    try {
      await sleep(500);
      yield 42;
    } catch (e) {
      console.error(e);
    }
  }
}

const asyncGen = createAsyncGenerator();
asyncGen.next(1).then((res) => console.log(res)); // { value: 42, done: false }
asyncGen
  .throw(new Error("Something went wrong")) // Error: Something went wrong
  .then((res) => console.log(res)); // { value: 42, done: false }
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-asyncgenerator-prototype-throw |

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

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

See also
--------

* `async function*`
* Iterators and generators guide
DataView.prototype.setInt16()
=============================

The **`setInt16()`** method of `DataView` instances takes a number and stores it as a 16-bit signed integer in the 2 bytes starting at the specified byte offset of this `DataView`. There is no alignment constraint; multi-byte values may be stored at any offset within bounds.

Try it
------

Syntax
------


```js
setInt16(byteOffset, value)
setInt16(byteOffset, value, littleEndian)
```

### Parameters

`byteOffset`

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

`value`

The value to set. For how the value is encoded in bytes, see Value encoding and normalization.

`littleEndian` Optional

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

### Return value

`undefined`.

### Exceptions

`RangeError`

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

Examples
--------

### Using setInt16()


```js
const buffer = new ArrayBuffer(10);
const dataview = new DataView(buffer);
dataview.setInt16(0, 3);
dataview.getInt16(1); // 768
```

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

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

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`
* `Int16Array`
DataView.prototype.setFloat32()
===============================

The **`setFloat32()`** method of `DataView` instances takes a number and stores it as a 32-bit floating point number in the 4 bytes starting at the specified byte offset of this `DataView`. There is no alignment constraint; multi-byte values may be stored at any offset within bounds.

Try it
------

Syntax
------


```js
setFloat32(byteOffset, value)
setFloat32(byteOffset, value, littleEndian)
```

### Parameters

`byteOffset`

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

`value`

The value to set. For how the value is encoded in bytes, see Value encoding and normalization.

`littleEndian` Optional

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

### Return value

`undefined`.

### Exceptions

`RangeError`

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

Examples
--------

### Using setFloat32()


```js
const buffer = new ArrayBuffer(10);
const dataview = new DataView(buffer);
dataview.setFloat32(0, 3);
dataview.getFloat32(1); // 2
```

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

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

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`
* `Float32Array`
DataView.prototype.getUint8()
=============================

The **`getUint8()`** method of `DataView` instances reads 1 byte at the specified byte offset of this `DataView` and interprets it as an 8-bit unsigned integer.

Try it
------

Syntax
------


```js
getUint8(byteOffset)
```

### Parameters

`byteOffset`

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

### Return value

An integer from 0 to 255, inclusive.

### Exceptions

`RangeError`

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

Examples
--------

### Using getUint8()


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

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

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

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`
* `Uint8Array`
DataView.prototype.setUint16()
==============================

The **`setUint16()`** method of `DataView` instances takes a number and stores it as a 16-bit unsigned integer in the 2 bytes starting at the specified byte offset of this `DataView`. There is no alignment constraint; multi-byte values may be stored at any offset within bounds.

Try it
------

Syntax
------


```js
setUint16(byteOffset, value)
setUint16(byteOffset, value, littleEndian)
```

### Parameters

`byteOffset`

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

`value`

The value to set. For how the value is encoded in bytes, see Value encoding and normalization.

`littleEndian` Optional

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

### Return value

`undefined`.

### Exceptions

`RangeError`

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

Examples
--------

### Using setUint16()


```js
const buffer = new ArrayBuffer(10);
const dataview = new DataView(buffer);
dataview.setUint16(0, 3);
dataview.getUint16(1); // 768
```

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

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

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`