Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. BigInt
  6. BigInt()

BigInt() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨September 2020⁩.

TheBigInt() function returns primitive values of type BigInt.

Syntax

js
BigInt(value)

Note:BigInt() can only be called withoutnew. Attempting to construct it withnew throws aTypeError.

Parameters

value

The value to be converted to a BigInt value. It may be a string, an integer, a boolean, or anotherBigInt.

Return value

ABigInt value. Number values must be integers and are converted to BigInts. The boolean valuetrue becomes1n, andfalse becomes0n. Strings are parsed as if they are source text for integer literals, which means they can have leading and trailing whitespaces and can be prefixed with0b,0o, or0x.

Exceptions

RangeError

Thrown if the parameter is a non-integral number.

TypeError

Thrown in one of the following cases:

  • The parameter cannot be converted to a primitive.
  • After conversion to a primitive, the result isundefined,null,symbol.
SyntaxError

Thrown if the parameter is a string that cannot be parsed as aBigInt.

Examples

Using BigInt() to convert a number to a BigInt

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

js
BigInt(123); // 123nBigInt(123.3); // RangeError: The number 123.3 cannot be converted to a BigInt because it is not an integer

Using string values

js
BigInt("123"); // 123nBigInt("0b10101"); // 21n, which is 10101 in binaryBigInt("0o123"); // 83n, which is 123 in octalBigInt("0x123"); // 291n, which is 123 in hexadecimalBigInt("  123  "); // 123n, leading and trailing whitespaces are allowed

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-bigint-constructor

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp