Python VS JavaScript – What are the Key Differences Between The ...
The main difference between these two approaches is that in Python, the user will be prompted to enter a value in the console while in ...
BigInt
A number literal like `37` in JavaScript code is a floating-point value, not an integer. There is no separate integer type in common everyday use. (JavaScript now has a <anchor>BigInt</anchor> type, but it was not designed to replace Number for everyday uses. `37` is still a Number, not a BigInt.)
BigInt - JavaScript | MDN
BigInt - JavaScript \| MDN

- [Skip to main content](#content)
- [Skip to search](#top-nav-search-input)
- [Skip to select language](#languages-switcher-button)

[MDN Web Docs](/en-US/) Open main menu

- References [References](/en-US/docs/Web)
  - [Overview / Web Technology\
    \
    Web technology reference for developers](/en-US/docs/Web)
  - [HTML\
    \
    Structure of content on the web](/en-US/docs/Web/HTML)
  - [CSS\
    \
    Code used to describe document style](/en-US/docs/Web/CSS)
  - [JavaScript\
    \
    General-purpose scripting language](/en-US/docs/Web/JavaScript)
  - [HTTP\
    \
    Protocol for transmitting web resources](/en-US/docs/Web/HTTP)
  - [Web APIs\
    \
    Interfaces for building web applications](/en-US/docs/Web/API)
  - [Web Extensions\
    \
    Developing extensions for web browsers](/en-US/docs/Mozilla/Add-ons/WebExtensions)
  - [Web Technology\
    \
    Web technology reference for developers](/en-US/docs/Web)
- Guides [Guides](/en-US/docs/Learn)
  - [Overview / MDN Learning Area\
    \
    Learn web development](/en-US/docs/Learn)
  - [MDN Learning Area\
    \
    Learn web development](/en-US/docs/Learn)
  - [HTML\
    \
    Learn to structure web content with HTML](/en-US/docs/Learn/HTML)
  - [CSS\
    \
    Learn to style content using CSS](/en-US/docs/Learn/CSS)
  - [JavaScript\
    \
    Learn to run scripts in the browser](/en-US/docs/Learn/JavaScript)
  - [Accessibility\
    \
    Learn to make the web accessible to all](/en-US/docs/Web/Accessibility)
- Plus [Plus](/en-US/plus)
  - [Overview\
    \
    A customized MDN experience](/en-US/plus)
  - [AI Help\
    \
    Get real-time assistance and support](/en-US/plus/ai-help)
  - [Updates\
    \
    All browser compatibility updates at a glance](/en-US/plus/updates)
  - [Documentation\
    \
    Learn how to use MDN Plus](/en-US/plus/docs/features/overview)
  - [FAQ\
    \
    Frequently asked questions about MDN Plus](/en-US/plus/docs/faq)
- [Curriculum](/en-US/curriculum/)
- [Blog](/en-US/blog/)
- Tools
  - [Playground\
    \
    Write, test and share your code](/en-US/play)
  - [HTTP Observatory\
    \
    Scan a website for free](/en-US/observatory)
  - [AI Help\
    \
    Get real-time assistance and support](/en-US/plus/ai-help)

Search MDNClear search inputSearch

Theme

- [Log in](/users/fxa/login/authenticate/?next=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FBigInt)
- [Sign up for free](/users/fxa/login/authenticate/?next=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FBigInt)

1. [References](/en-US/docs/Web)
2. [JavaScript](/en-US/docs/Web/JavaScript)
3. [Reference](/en-US/docs/Web/JavaScript/Reference)
4. [Standard built-in objects](/en-US/docs/Web/JavaScript/Reference/Global_Objects)
5. [BigInt](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)

Article Actions

- English (US)



- [Español](/es/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [Français](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [日本語](/ja/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [한국어](/ko/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [Português (do Brasil)](/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [Русский](/ru/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [中文 (简体)](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [正體中文 (繁體)](/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/BigInt)

Filter sidebarClear filter input

## In this article

- [Description](#description)
- [Constructor](#constructor)
- [Static methods](#static_methods)
- [Instance properties](#instance_properties)
- [Instance methods](#instance_methods)
- [Examples](#examples)
- [Specifications](#specifications)
- [Browser compatibility](#browser_compatibility)
- [See also](#see_also)

01. [Standard built-in objects](/en-US/docs/Web/JavaScript/Reference/Global_Objects)
02. _[`BigInt`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)_
03. Constructor

1. [`BigInt() constructor`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)

04. Static methods

1. [`BigInt.asIntN()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
2. [`BigInt.asUintN()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)

05. Instance methods

1. [`BigInt.prototype.toLocaleString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2. [`BigInt.prototype.toString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3. [`BigInt.prototype.valueOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)

06. Inheritance
07. [`Object/Function`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
08. Static methods

1. [`Function.prototype.apply()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
2. [`Function.prototype.bind()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
3. [`Function.prototype.call()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4. [`Function.prototype[Symbol.hasInstance]()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Symbol.hasInstance)
5. [`Function.prototype.toString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)

09. Static properties

1. [`Function.prototype.arguments`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/arguments)Non-standardDeprecated
2. [`Function.prototype.caller`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller)Non-standardDeprecated
3. [`Function: displayName`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/displayName)Non-standard
4. [`Function: length`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
5. [`Function: name`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
6. [`Function: prototype`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype)

10. Instance methods

01. [`Object.prototype.__defineGetter__()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__)Deprecated
02. [`Object.prototype.__defineSetter__()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__)Deprecated
03. [`Object.prototype.__lookupGetter__()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__)Deprecated
04. [`Object.prototype.__lookupSetter__()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__)Deprecated
05. [`Object.prototype.hasOwnProperty()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
06. [`Object.prototype.isPrototypeOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
07. [`Object.prototype.propertyIsEnumerable()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
08. [`Object.prototype.toLocaleString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
09. [`Object.prototype.toString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
10. [`Object.prototype.valueOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)

11. Instance properties

1. [`Object.prototype.constructor`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
2. [`Object.prototype.__proto__`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto)Deprecated

## In this article

- [Description](#description)
- [Constructor](#constructor)
- [Static methods](#static_methods)
- [Instance properties](#instance_properties)
- [Instance methods](#instance_methods)
- [Examples](#examples)
- [Specifications](#specifications)
- [Browser compatibility](#browser_compatibility)
- [See also](#see_also)

# BigInt

## BaselineWidely available

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

- [Learn more](/en-US/docs/Glossary/Baseline/Compatibility)
- [See full compatibility](#browser_compatibility)
- [Report feedback](https://survey.alchemer.com/s3/7634825/MDN-baseline-feedback?page=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FBigInt&level=high)

**`BigInt`** values represent numeric values which are [too large](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) to be represented by the `number` [primitive](/en-US/docs/Glossary/Primitive).

## [Description](\#description)

A **BigInt value**, also sometimes just called a **BigInt**, is a `bigint` [primitive](/en-US/docs/Glossary/Primitive), created by appending `n` to the end of an integer literal, or by calling the [`BigInt()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt) function (without the `new` operator) and giving it an integer value or string value.

js

```
const previouslyMaxSafeInteger = 9007199254740991n;

const alsoHuge = BigInt(9007199254740991);
// 9007199254740991n

const hugeString = BigInt("9007199254740991");
// 9007199254740991n

const hugeHex = BigInt("0x1fffffffffffff");
// 9007199254740991n

const hugeOctal = BigInt("0o377777777777777777");
// 9007199254740991n

const hugeBin = BigInt(
  "0b11111111111111111111111111111111111111111111111111111",
);
// 9007199254740991n

```

BigInt values are similar to Number values in some ways, but also differ in a few key matters: A BigInt value cannot be used with methods in the built-in [`Math`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) object and cannot be mixed with a Number value in operations; they must be coerced to the same type. Be careful coercing values back and forth, however, as the precision of a BigInt value may be lost when it is coerced to a Number value.

### [Type information](\#type_information)

When tested against `typeof`, a BigInt value ( `bigint` primitive) will give `"bigint"`:

js

```
typeof 1n === "bigint"; // true
typeof BigInt("1") === "bigint"; // true

```

A BigInt value can also be wrapped in an `Object`:

js

```
typeof Object(1n) === "object"; // true

```

### [Operators](\#operators)

Most operators support BigInts, however most do not permit operands to be of mixed types — both operands must be BigInt or neither:

- [Arithmetic operators](/en-US/docs/Web/JavaScript/Reference/Operators#arithmetic_operators): `+`, `-`, `*`, `/`, `%`, `**`
- [Bitwise operators](/en-US/docs/Web/JavaScript/Reference/Operators#bitwise_shift_operators): `>>`, `<<`, `&`, `|`, `^`, `~`
- [Unary negation ( `-`)](/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation)
- [Increment/decrement](/en-US/docs/Web/JavaScript/Reference/Operators#increment_and_decrement): `++`, `--`

The boolean-returning operators allow mixing numbers and BigInts as operands:

- [Relational operators](/en-US/docs/Web/JavaScript/Reference/Operators#relational_operators) and [equality operators](/en-US/docs/Web/JavaScript/Reference/Operators#equality_operators): `>`, `<`, `>=`, `<=`, `==`, `!=`, `===`, `!==`
- [Logical operators](/en-US/docs/Web/JavaScript/Reference/Operators#binary_logical_operators) only rely on the [truthiness](/en-US/docs/Glossary/Truthy) of operands

A couple of operators do not support BigInt at all:

- [Unary plus ( `+`)](/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus) cannot be supported due to conflicting usage in asm.js, so it has been left out [in order to not break asm.js](https://github.com/tc39/proposal-bigint/blob/master/ADVANCED.md#dont-break-asmjs).
- [Unsigned right shift ( `>>>`)](/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift) is the only bitwise operator that's unsupported, as every BigInt value is signed.

Special cases:

- Addition ( `+`) involving a string and a BigInt returns a string.
- Division ( `/`) truncates fractional components towards zero, since BigInt is unable to represent fractional quantities.

js

```
const previousMaxSafe = BigInt(Number.MAX_SAFE_INTEGER); // 9007199254740991n
const maxPlusOne = previousMaxSafe + 1n; // 9007199254740992n
const theFuture = previousMaxSafe + 2n; // 9007199254740993n, this works now!
const multi = previousMaxSafe * 2n; // 18014398509481982n
const subtr = multi - 10n; // 18014398509481972n
const mod = multi % 10n; // 2n
const bigN = 2n ** 54n; // 18014398509481984n
bigN * -1n; // -18014398509481984n
const expected = 4n / 2n; // 2n
const truncated = 5n / 2n; // 2n, not 2.5n

```

### [Comparisons](\#comparisons)

A BigInt value is not strictly equal to a Number value, but it _is_ loosely so:

js

```
0n === 0; // false
0n == 0; // true

```

A Number value and a BigInt value may be compared as usual:

js

```
1n < 2; // true
2n > 1; // true
2 > 2; // false
2n > 2; // false
2n >= 2; // true

```

BigInt values and Number values may be mixed in arrays and sorted:

js

```
const mixed = [4n, 6, -12n, 10, 4, 0, 0n];
// [4n, 6, -12n, 10, 4, 0, 0n]

mixed.sort(); // default sorting behavior
// [ -12n, 0, 0n, 10, 4n, 4, 6 ]

mixed.sort((a, b) => a - b);
// won't work since subtraction will not work with mixed types
// TypeError: can't convert BigInt value to Number value

// sort with an appropriate numeric comparator
mixed.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
// [ -12n, 0, 0n, 4n, 4, 6, 10 ]

```

Note that comparisons with `Object`-wrapped BigInt values act as with other objects, only indicating equality when the same object instance is compared:

js

```
Object(0n) === 0n; // false
Object(0n) === Object(0n); // false

const o = Object(0n);
o === o; // true

```

Because coercing between Number values and BigInt values can lead to loss of precision, the following are recommended:

- Only use a BigInt value when values greater than 253 are reasonably expected.
- Don't coerce between BigInt values and Number values.

### [Conditionals](\#conditionals)

A BigInt value follows the same conversion rules as Numbers when:

- it is converted to a [`Boolean`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean): via the [`Boolean`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) function;
- when used with [logical operators](/en-US/docs/Web/JavaScript/Reference/Operators) `||`, `&&`, and `!`; or
- within a conditional test like an [`if`](/en-US/docs/Web/JavaScript/Reference/Statements/if...else) statement.

Namely, only `0n` is [falsy](/en-US/docs/Glossary/Falsy); everything else is [truthy](/en-US/docs/Glossary/Truthy).

js

```
if (0n) {
  console.log("Hello from the if!");
} else {
  console.log("Hello from the else!");
}
// "Hello from the else!"

0n || 12n; // 12n
0n && 12n; // 0n
Boolean(0n); // false
Boolean(12n); // true
!12n; // false
!0n; // true

```

### [Cryptography](\#cryptography)

The operations supported on BigInt values are not constant-time and are thus open to [timing attacks](https://en.wikipedia.org/wiki/Timing_attack). JavaScript BigInts therefore could be dangerous for use in cryptography without mitigating factors. As a very generic example, an attacker could measure the time difference between `101n ** 65537n` and `17n ** 9999n`, and deduce the magnitude of secrets, such as private keys, based on the time elapsed. If you still have to use BigInts, take a look at the [Timing attack FAQ](https://timing.attacks.cr.yp.to/programming.html) for general advice regarding the issue.

### [Use within JSON](\#use_within_json)

Using [`JSON.stringify()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) with any BigInt value will raise a `TypeError`, as BigInt values aren't serialized in JSON by default. However, `JSON.stringify()` specifically leaves a backdoor for BigInt values: it would try to call the BigInt's `toJSON()` method. (It doesn't do so for any other primitive values.) Therefore, you can implement your own `toJSON()` method (which is one of the few cases where patching built-in objects is not explicitly discouraged):

js

```
BigInt.prototype.toJSON = function () {
  return { $bigint: this.toString() };
};

```

Instead of throwing, `JSON.stringify()` now produces a string like this:

js

```
console.log(JSON.stringify({ a: 1n }));
// {"a":{"$bigint":"1"}}

```

If you do not wish to patch `BigInt.prototype`, you can use the [`replacer`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter) parameter of `JSON.stringify` to serialize BigInt values:

js

```
const replacer = (key, value) =>
  typeof value === "bigint" ? { $bigint: value.toString() } : value;

const data = {
  number: 1,
  big: 18014398509481982n,
};
const stringified = JSON.stringify(data, replacer);

console.log(stringified);
// {"number":1,"big":{"$bigint":"18014398509481982"}}

```

You can then use the [`reviver`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter) parameter of `JSON.parse` to handle them:

js

```
const reviver = (key, value) =>
  value !== null &&
  typeof value === "object" &&
  "$bigint" in value &&
  typeof value.$bigint === "string"
    ? BigInt(value.$bigint)
    : value;

const payload = '{"number":1,"big":{"$bigint":"18014398509481982"}}';
const parsed = JSON.parse(payload, reviver);

console.log(parsed);
// { number: 1, big: 18014398509481982n }

```

**Note:** While it's possible to make the replacer of `JSON.stringify()` generic and properly serialize BigInt values for all objects as shown above, the reviver of `JSON.parse()` has to be used with caution, because the serialization is _irreversible_: it's not possible to distinguish between an object that happens to have a property called `$bigint` and an actual BigInt.

In addition, the example above creates an entire object during replacing and reviving, which may have performance or storage implications for larger objects containing many BigInts. If you know the shape of the payload, it may be better to just serialize them as strings and revive them based on the property key's name instead.

In fact, JSON allows number literals that are arbitrarily long; they just cannot be parsed to full precision in JavaScript. If you are communicating with another program in a language that supports longer integers (such as 64-bit integers), and you want to transmit the BigInt as a JSON number instead of a JSON string, see [Lossless number serialization](/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON#using_json_numbers).

### [BigInt coercion](\#bigint_coercion)

Many built-in operations that expect BigInts first coerce their arguments to BigInts. [The operation](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tobigint) can be summarized as follows:

- BigInts are returned as-is.
- [`undefined`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) and [`null`](/en-US/docs/Web/JavaScript/Reference/Operators/null) throw a [`TypeError`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError).
- `true` turns into `1n`; `false` turns into `0n`.
- Strings are converted by parsing them as if they contain an integer literal. Any parsing failure results in a [`SyntaxError`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError). The syntax is a subset of [string numeric literals](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_coercion), where decimal points or exponent indicators are not allowed.
- [Numbers](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) throw a [`TypeError`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) to prevent unintended implicit coercion causing loss of precision.
- [Symbols](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) throw a [`TypeError`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError).
- Objects are first [converted to a primitive](/en-US/docs/Web/JavaScript/Data_structures#primitive_coercion) by calling their [`[Symbol.toPrimitive]()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive) (with `"number"` as hint), `valueOf()`, and `toString()` methods, in that order. The resulting primitive is then converted to a BigInt.

The best way to achieve nearly the same effect in JavaScript is through the [`BigInt()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt) function: `BigInt(x)` uses the same algorithm to convert `x`, except that [Numbers](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) don't throw a [`TypeError`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError), but are converted to BigInts if they are integers.

Note that built-in operations expecting BigInts often truncate the BigInt to a fixed width after coercion. This includes [`BigInt.asIntN()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN), [`BigInt.asUintN()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN), and methods of [`BigInt64Array`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array) and [`BigUint64Array`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array).

## [Constructor](\#constructor)

[`BigInt()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)

Returns primitive values of type BigInt. Throws an error when called with `new`.

## [Static methods](\#static_methods)

[`BigInt.asIntN()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)

Clamps a BigInt value to a signed integer value, and returns that value.

[`BigInt.asUintN()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)

Clamps a BigInt value to an unsigned integer value, and returns that value.

## [Instance properties](\#instance_properties)

These properties are defined on `BigInt.prototype` and shared by all `BigInt` instances.

[`BigInt.prototype.constructor`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)

The constructor function that created the instance object. For `BigInt` instances, the initial value is the [`BigInt`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt) constructor.

[`BigInt.prototype[Symbol.toStringTag]`](#bigint.prototypesymbol.tostringtag)

The initial value of the [`[Symbol.toStringTag]`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) property is the string `"BigInt"`. This property is used in [`Object.prototype.toString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString). However, because `BigInt` also has its own [`toString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString) method, this property is not used unless you call [`Object.prototype.toString.call()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) with a BigInt as `thisArg`.

## [Instance methods](\#instance_methods)

[`BigInt.prototype.toLocaleString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)

Returns a string with a language-sensitive representation of this BigInt value. Overrides the [`Object.prototype.toLocaleString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString) method.

[`BigInt.prototype.toString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)

Returns a string representing this BigInt value in the specified radix (base). Overrides the [`Object.prototype.toString()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString) method.

[`BigInt.prototype.valueOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)

Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.

## [Examples](\#examples)

### [Calculating Primes](\#calculating_primes)

js

```
// Returns true if the passed BigInt value is a prime number
function isPrime(p) {
  for (let i = 2n; i * i <= p; i++) {
    if (p % i === 0n) return false;
  }
  return true;
}

// Takes a BigInt value as an argument, returns nth prime number as a BigInt value
function nthPrime(nth) {
  let maybePrime = 2n;
  let prime = 0n;

  while (nth >= 0n) {
    if (isPrime(maybePrime)) {
      nth--;
      prime = maybePrime;
    }
    maybePrime++;
  }

  return prime;
}

nthPrime(20n);
// 73n

```

## [Specifications](\#specifications)

Specification[ECMAScript Language Specification\
\# sec-bigint-objects](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-bigint-objects)

## [Browser compatibility](\#browser_compatibility)

BCD tables only load in the browser

## [See also](\#see_also)

- [`Number`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- [`Number.MAX_SAFE_INTEGER`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)

## Help improve MDN

Was this page helpful to you?

YesNo

[Learn how to contribute](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you to our contribution guidelines on GitHub.").

This page was last modified onJul 25, 2024 by [MDN contributors](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/contributors.txt).

[View this page on GitHub](https://github.com/mdn/content/blob/main/files/en-us/web/javascript/reference/global_objects/bigint/index.md?plain=1 "Folder: en-us/web/javascript/reference/global_objects/bigint (Opens in a new tab)")• [Report a problem with this content](https://github.com/mdn/content/issues/new?template=page-report.yml&mdn-url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FBigInt&metadata=%3C%21--+Do+not+make+changes+below+this+line+--%3E%0A%3Cdetails%3E%0A%3Csummary%3EPage+report+details%3C%2Fsummary%3E%0A%0A*+Folder%3A+%60en-us%2Fweb%2Fjavascript%2Freference%2Fglobal_objects%2Fbigint%60%0A*+MDN+URL%3A+https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FBigInt%0A*+GitHub+URL%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fblob%2Fmain%2Ffiles%2Fen-us%2Fweb%2Fjavascript%2Freference%2Fglobal_objects%2Fbigint%2Findex.md%0A*+Last+commit%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fcommit%2F8421c0cd94fa5aa237c833ac6d24885edbc7d721%0A*+Document+last+modified%3A+2024-07-25T21%3A32%3A46.000Z%0A%0A%3C%2Fdetails%3E "This will take you to GitHub to file a new issue.")

[MDN logo](/)

Your blueprint for a better internet.

- [MDN on Mastodon](https://mozilla.social/@mdn)
- [MDN on X (formerly Twitter)](https://twitter.com/mozdevnet)
- [MDN on GitHub](https://github.com/mdn/)
- [MDN Blog RSS Feed](/en-US/blog/rss.xml)

## MDN

- [About](/en-US/about)
- [Blog](/en-US/blog/)
- [Careers](https://www.mozilla.org/en-US/careers/listings/?team=ProdOps)
- [Advertise with us](/en-US/advertising)

## Support

- [Product help](https://support.mozilla.org/products/mdn-plus)
- [Report an issue](/en-US/docs/MDN/Community/Issues)

## Our communities

- [MDN Community](/en-US/community)
- [MDN Forum](https://discourse.mozilla.org/c/mdn/236)
- [MDN Chat](/discord)

## Developers

- [Web Technologies](/en-US/docs/Web)
- [Learn Web Development](/en-US/docs/Learn)
- [MDN Plus](/en-US/plus)
- [Hacks Blog](https://hacks.mozilla.org/)

[Mozilla logo](https://www.mozilla.org/)

- [Website Privacy Notice](https://www.mozilla.org/privacy/websites/)
- [Cookies](https://www.mozilla.org/privacy/websites/#cookies)
- [Legal](https://www.mozilla.org/about/legal/terms/mozilla)
- [Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/)

Visit [Mozilla Corporation’s](https://www.mozilla.org) not-for-profit parent, the [Mozilla Foundation](https://foundation.mozilla.org/).

Portions of this content are ©1998–2024 by individual mozilla.org contributors. Content available under [a Creative Commons license](/en-US/docs/MDN/Writing_guidelines/Attrib_copyright_license).