recursal/MDN huggingface dataset:
AsyncFunction() constructor
===========================

Baseline Widely available
-------------------------

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2017.

* Learn more
* See full compatibility
* Report feedback
The **`AsyncFunction()`** constructor creates `AsyncFunction` objects.

Note that `AsyncFunction` is *not* a global object. It can be obtained with the following code:


```js
const AsyncFunction = async function () {}.constructor;
```


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

Syntax
------


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

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


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

### Parameters

See `Function()`.

Examples
--------

### Creating an async function from an AsyncFunction() constructor


```js
function resolveAfter2Seconds(x) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

const AsyncFunction = async function () {}.constructor;

const fn = new AsyncFunction(
  "a",
  "b",
  "return await resolveAfter2Seconds(a) + await resolveAfter2Seconds(b);",
);

fn(10, 20).then((v) => {
  console.log(v); // prints 30 after 4 seconds
});
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-async-function-constructor |

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

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

See also
--------

* `async function`
* `async function` expression
* `Function()` constructor
Number() constructor
====================

The **`Number()`** constructor creates `Number` objects. When called as a function, it returns primitive values of type Number.

Syntax
------


```js
new Number(value)
Number(value)
```


**Note:** `Number()` can be called with or without `new`, but with different effects. See Return value.

### Parameters

`value`

The numeric value of the object being created.

### Return value

When `Number` is called as a constructor (with `new`), it creates a `Number` object, which is **not** a primitive.

When `Number` is called as a function, it coerces the parameter to a number primitive. BigInts are converted to numbers. If the value can't be converted, it returns `NaN`.

**Warning:** You should rarely find yourself using `Number` as a constructor.

Examples
--------

### Creating Number objects


```js
const a = new Number("123"); // a === 123 is false
const b = Number("123"); // b === 123 is true
a instanceof Number; // is true
b instanceof Number; // is false
typeof a; // "object"
typeof b; // "number"
```

### Using Number() to convert a BigInt to a number

`Number()` is the only case where a BigInt can be converted to a number without throwing, because it's very explicit.


```js
+1n; // TypeError: Cannot convert a BigInt value to a number
0 + 1n; // TypeError: Cannot mix BigInt and other types, use explicit conversions
```



```js
Number(1n); // 1
```


Note that this may result in loss of precision, if the BigInt is too large to be safely represented.


```js
BigInt(Number(2n \*\* 54n + 1n)) === 2n \*\* 54n + 1n; // false
```

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

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

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

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

See also
--------

* Polyfill of modern `Number` behavior (with support binary and octal literals) in `core-js`
* `NaN`
* `Math`
* `BigInt`
Number.prototype.toExponential()
================================

 The **`toExponential()`** method of `Number` values returns a string representing
 this number in exponential notation.

Try it
------

Syntax
------


```js
toExponential()
toExponential(fractionDigits)
```

### Parameters

`fractionDigits` Optional

 Optional. An integer specifying the number of digits after the decimal point.
 Defaults to as many digits as necessary to specify the number.


### Return value

 A string representing the given `Number` object in exponential notation
 with one digit before the decimal point, rounded to
 `fractionDigits` digits after the decimal point.

### Exceptions

`RangeError`

Thrown if `fractionDigits` is not between `0` and `100` (inclusive).

`TypeError`

Thrown if this method is invoked on an object that is not a `Number`.

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

 If the `fractionDigits` argument is omitted, the number of digits
 after the decimal point defaults to the number of digits necessary to represent the
 value uniquely.

 If you use the `toExponential()` method for a numeric literal and the
 numeric literal has no exponent and no decimal point, leave whitespace(s) before the dot
 that precedes the method call to prevent the dot from being interpreted as a decimal
 point.

 If a number has more digits than requested by the
 `fractionDigits` parameter, the number is rounded to the nearest
 number represented by `fractionDigits` digits. See the discussion
 of rounding in the description of the `toFixed()` method, which also applies to `toExponential()`.

Examples
--------

### Using toExponential


```js
const numObj = 77.1234;

console.log(numObj.toExponential()); // 7.71234e+1
console.log(numObj.toExponential(4)); // 7.7123e+1
console.log(numObj.toExponential(2)); // 7.71e+1
console.log((77.1234).toExponential()); // 7.71234e+1
console.log((77).toExponential()); // 7.7e+1
```

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

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

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

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

See also
--------

* Polyfill of `Number.prototype.toExponential` with many bug fixes in `core-js`
* `Number.prototype.toFixed()`
* `Number.prototype.toPrecision()`
* `Number.prototype.toString()`
Number.MIN\_SAFE\_INTEGER
=========================

The **`Number.MIN_SAFE_INTEGER`** static data property represents the minimum safe integer in JavaScript, or -(253 - 1).

To represent integers smaller than this, consider using `BigInt`.

Try it
------

Value
-----

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

| Property attributes of `Number.MIN_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 correctly compare them. For example, `Number.MIN_SAFE_INTEGER - 1 === Number.MIN_SAFE_INTEGER - 2` will evaluate to true, which is mathematically incorrect. See `Number.isSafeInteger()` for more information.

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

Examples
--------

### Using MIN\_SAFE\_INTEGER


```js
Number.MIN\_SAFE\_INTEGER; // -9007199254740991
-(2 \*\* 53 - 1); // -9007199254740991
```

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

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

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

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

See also
--------

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

The **`Number.MIN_VALUE`** static data property represents the smallest positive numeric value representable in JavaScript.

Try it
------

Value
-----

2-1074, or `5E-324`.

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

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

`Number.MIN_VALUE` is the smallest positive number (not the most negative number) that can be represented within float precision — in other words, the number closest to 0. The ECMAScript spec doesn't define a precise value that implementations are required to support — instead the spec says, *"must be the smallest non-zero positive value that can actually be represented by the implementation"*. This is because small IEEE-754 floating point numbers are denormalized, but implementations are not required to support this representation, in which case `Number.MIN_VALUE` may be larger.

In practice, its precise value in mainstream engines like V8 (used by Chrome, Edge, Node.js), SpiderMonkey (used by Firefox), and JavaScriptCore (used by Safari) is 2-1074, or `5E-324`.

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

Examples
--------

### Using MIN\_VALUE

The following code divides two numeric values. If the result is greater than or equal to `MIN_VALUE`, the `func1` function is called; otherwise, the `func2` function is called.


```js
if (num1 / num2 >= Number.MIN\_VALUE) {
  func1();
} else {
  func2();
}
```

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

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

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

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

See also
--------

* `Number.MAX_VALUE`
Number.POSITIVE\_INFINITY
=========================

The **`Number.POSITIVE_INFINITY`** static data property represents the positive Infinity value.

Try it
------

Value
-----

The same as the value of the global `Infinity` property.

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

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

The `Number.POSITIVE_INFINITY` value behaves slightly differently than mathematical infinity:

* Any positive value, including `POSITIVE_INFINITY`, multiplied by `POSITIVE_INFINITY` is `POSITIVE_INFINITY`.
* Any negative value, including `NEGATIVE_INFINITY`, multiplied by `POSITIVE_INFINITY` is `NEGATIVE_INFINITY`.
* Any positive number divided by `POSITIVE_INFINITY` is positive zero (as defined in IEEE 754).
* Any negative number divided by `POSITIVE_INFINITY` is negative zero (as defined in IEEE 754.
* Zero multiplied by `POSITIVE_INFINITY` is `NaN`.
* `NaN` multiplied by `POSITIVE_INFINITY` is `NaN`.
* `POSITIVE_INFINITY`, divided by any negative value except `NEGATIVE_INFINITY`, is `NEGATIVE_INFINITY`.
* `POSITIVE_INFINITY`, divided by any positive value except `POSITIVE_INFINITY`, is `POSITIVE_INFINITY`.
* `POSITIVE_INFINITY`, divided by either `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`, is `NaN`.
* `Number.POSITIVE_INFINITY > x` is true for any number *x* that isn't `POSITIVE_INFINITY`.

You might use the `Number.POSITIVE_INFINITY` property to indicate an error condition that returns a finite number in case of success. Note, however, that `NaN` would be more appropriate in such a case.

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

Examples
--------

### Using POSITIVE\_INFINITY

In the following example, the variable `bigNumber` is assigned a value that is larger than the maximum value. When the `if` statement executes, `bigNumber` has the value `Infinity`, so `bigNumber` is set to a more manageable value before continuing.


```js
let bigNumber = Number.MAX\_VALUE \* 2;

if (bigNumber === Number.POSITIVE\_INFINITY) {
  bigNumber = returnFinite();
}
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-number.positive\_infinity |

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

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

See also
--------

* `Number.NEGATIVE_INFINITY`
* `Number.isFinite()`
* `Infinity`
* `isFinite()`
Number.parseFloat()
===================

The **`Number.parseFloat()`** static method parses an argument and returns a floating point number. If a number cannot be parsed from the argument, it returns `NaN`.

Try it
------

Syntax
------


```js
Number.parseFloat(string)
```

### Parameters

`string`

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

### Return value

A floating point number parsed from the given `string`.

Or `NaN` when the first non-whitespace character cannot be converted to a number.

Examples
--------

### Number.parseFloat vs. parseFloat

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


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


Its purpose is modularization of globals.

See `parseFloat()` for more detail and examples.

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

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

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

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

See also
--------

* Polyfill of `Number.parseFloat` in `core-js`
* `Number`
* `parseFloat()`
Number.isNaN()
==============

The **`Number.isNaN()`** static method determines whether the passed value is the number value `NaN`, and returns `false` if the input is not of the Number type. It is a more robust version of the original, global `isNaN()` function.

Try it
------

Syntax
------


```js
Number.isNaN(value)
```

### Parameters

`value`

The value to be tested for `NaN`.

### Return value

The boolean value `true` if the given value is a number with value `NaN`. Otherwise, `false`.

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

The function `Number.isNaN()` provides a convenient way to check for equality with `NaN`. Note that you cannot test for equality with `NaN` using either the `==` or `===` operators, because unlike all other value comparisons in JavaScript, these evaluate to `false` whenever one operand is `NaN`, even if the other operand is also `NaN`.

Since `x !== x` is only true for `NaN` among all possible JavaScript values, `Number.isNaN(x)` can also be replaced with a test for `x !== x`, despite the latter being less readable.

As opposed to the global `isNaN()` function, the `Number.isNaN()` method doesn't force-convert the parameter to a number. This makes it safe to pass values that would normally convert to `NaN` but aren't actually the same value as `NaN`. This also means that only values of the Number type that are also `NaN` return `true`.

Examples
--------

### Using isNaN()


```js
Number.isNaN(NaN); // true
Number.isNaN(Number.NaN); // true
Number.isNaN(0 / 0); // true
Number.isNaN(37); // false
```

### Difference between Number.isNaN() and global isNaN()

`Number.isNaN()` doesn't attempt to convert the parameter to a number, so non-numbers always return `false`. The following are all `false`:


```js
Number.isNaN("NaN");
Number.isNaN(undefined);
Number.isNaN({});
Number.isNaN("blabla");
Number.isNaN(true);
Number.isNaN(null);
Number.isNaN("37");
Number.isNaN("37.37");
Number.isNaN("");
Number.isNaN(" ");
```


The global `isNaN()` coerces its parameter to a number:


```js
isNaN("NaN"); // true
isNaN(undefined); // true
isNaN({}); // true
isNaN("blabla"); // true
isNaN(true); // false, this is coerced to 1
isNaN(null); // false, this is coerced to 0
isNaN("37"); // false, this is coerced to 37
isNaN("37.37"); // false, this is coerced to 37.37
isNaN(""); // false, this is coerced to 0
isNaN(" "); // false, this is coerced to 0
```

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

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

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

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

See also
--------

* Polyfill of `Number.isNaN` in `core-js`
* `Number`
* `isNaN()`
Number.isFinite()
=================

The **`Number.isFinite()`** static method determines whether the passed value is a finite number — that is, it checks that a given value is a number, and the number is neither positive `Infinity`, negative `Infinity`, nor `NaN`.

Try it
------

Syntax
------


```js
Number.isFinite(value)
```

### Parameters

`value`

The value to be tested for finiteness.

### Return value

The boolean value `true` if the given value is a finite number. Otherwise `false`.

Examples
--------

### Using isFinite()


```js
Number.isFinite(Infinity); // false
Number.isFinite(NaN); // false
Number.isFinite(-Infinity); // false

Number.isFinite(0); // true
Number.isFinite(2e64); // true
```

### Difference between Number.isFinite() and global isFinite()

In comparison to the global `isFinite()` function, this method doesn't first convert the parameter to a number. This means only values of the type number *and* are finite return `true`, and non-numbers always return `false`.


```js
isFinite("0"); // true; coerced to number 0
Number.isFinite("0"); // false
isFinite(null); // true; coerced to number 0
Number.isFinite(null); // false
```

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

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

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

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

See also
--------

* Polyfill of `Number.isFinite` in `core-js`
* `Number`
* `isFinite()`
Number.prototype.toPrecision()
==============================

 The **`toPrecision()`** method of `Number` values returns a string representing
 this number to the specified precision.

Try it
------

Syntax
------


```js
toPrecision()
toPrecision(precision)
```

### Parameters

`precision` Optional

An integer specifying the number of significant digits.

### Return value

 A string representing a `Number` object in fixed-point or exponential
 notation rounded to `precision` significant digits. See the discussion of
 rounding in the description of the `Number.prototype.toFixed()` method,
 which also applies to `toPrecision()`.

 If the `precision` argument is omitted, behaves as
 `Number.prototype.toString()`. If the `precision` argument is a
 non-integer value, it is rounded to the nearest integer.

### Exceptions

`RangeError`

Thrown if `precision` is not between `1` and `100` (inclusive).

Examples
--------

### Using `toPrecision`


```js
let num = 5.123456;

console.log(num.toPrecision()); // '5.123456'
console.log(num.toPrecision(5)); // '5.1235'
console.log(num.toPrecision(2)); // '5.1'
console.log(num.toPrecision(1)); // '5'

num = 0.000123;

console.log(num.toPrecision()); // '0.000123'
console.log(num.toPrecision(5)); // '0.00012300'
console.log(num.toPrecision(2)); // '0.00012'
console.log(num.toPrecision(1)); // '0.0001'

// note that exponential notation might be returned in some circumstances
console.log((1234.5).toPrecision(2)); // '1.2e+3'
```

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

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

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

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

See also
--------

* `Number.prototype.toFixed()`
* `Number.prototype.toExponential()`
* `Number.prototype.toString()`
Number.NEGATIVE\_INFINITY
=========================

The **`Number.NEGATIVE_INFINITY`** static data property represents the negative Infinity value.

Try it
------

Value
-----

The same as the negative value of the global `Infinity` property.

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

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

The `Number.NEGATIVE_INFINITY` value behaves slightly differently than mathematical infinity:

* Any positive value, including `POSITIVE_INFINITY`, multiplied by `NEGATIVE_INFINITY` is `NEGATIVE_INFINITY`.
* Any negative value, including `NEGATIVE_INFINITY`, multiplied by `NEGATIVE_INFINITY` is `POSITIVE_INFINITY`.
* Any positive value divided by `NEGATIVE_INFINITY` is negative zero (as defined in IEEE 754).
* Any negative value divided by `NEGATIVE_INFINITY` is positive zero (as defined in IEEE 754).
* Zero multiplied by `NEGATIVE_INFINITY` is `NaN`.
* `NaN` multiplied by `NEGATIVE_INFINITY` is `NaN`.
* `NEGATIVE_INFINITY`, divided by any negative value except `NEGATIVE_INFINITY`, is `POSITIVE_INFINITY`.
* `NEGATIVE_INFINITY`, divided by any positive value except `POSITIVE_INFINITY`, is `NEGATIVE_INFINITY`.
* `NEGATIVE_INFINITY`, divided by either `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`, is `NaN`.
* `x > Number.NEGATIVE_INFINITY` is true for any number *x* that isn't `NEGATIVE_INFINITY`.

You might use the `Number.NEGATIVE_INFINITY` property to indicate an error condition that returns a finite number in case of success. Note, however, that `NaN` would be more appropriate in such a case.

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

Examples
--------

### Using NEGATIVE\_INFINITY

In the following example, the variable `smallNumber` is assigned a value that is smaller than the minimum value. When the `if` statement executes, `smallNumber` has the value `-Infinity`, so `smallNumber` is set to a more manageable value before continuing.


```js
let smallNumber = -Number.MAX\_VALUE \* 2;

if (smallNumber === Number.NEGATIVE\_INFINITY) {
  smallNumber = returnFinite();
}
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-number.negative\_infinity |

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

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

See also
--------

* `Number.POSITIVE_INFINITY`
* `Number.isFinite()`
* `Infinity`
* `isFinite()`
Number.NaN
==========

The **`Number.NaN`** static data property represents Not-A-Number, which is equivalent to `NaN`. For more information about the behaviors of `NaN`, see the description for the global property.

Try it
------

Value
-----

The number value `NaN`.

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

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

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

Examples
--------

### Checking whether values are numeric


```js
function sanitize(x) {
  if (isNaN(x)) {
    return Number.NaN;
  }
  return x;
}
```

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

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

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

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

See also
--------

* `NaN`
* `Number.isNaN()`