| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/BigInt | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2020 ..
BigInt , 253 - 1, , JavaScript Number . , Number.MAX_SAFE_INTEGER.
BigInt n 10n BigInt().
const theBiggestInt = 9007199254740991n;
const alsoHuge = BigInt(9007199254740991);
// 9007199254740991n
const hugeString = BigInt("9007199254740991");
// 9007199254740991n
const hugeHex = BigInt("0x1fffffffffffff");
// 9007199254740991n
const hugeBin = BigInt(
"0b11111111111111111111111111111111111111111111111111111",
);
// 9007199254740991n
:
Number BigInt .
, BigInt (Number).
typeof, BigInt "bigint":
typeof 1n === "bigint"; // true
typeof BigInt("1") === "bigint"; // true
, BigInt :
typeof Object(1n) === "object"; // true
BigInt ( - BigInt): +, *, -, **, %.
(+) asm.js.
const previousMaxSafe = BigInt(Number.MAX_SAFE_INTEGER);
// 9007199254740991n
const maxPlusOne = previousMaxSafe + 1n;
// 9007199254740992n
const theFuture = previousMaxSafe + 2n;
// 9007199254740993n, !
const multi = previousMaxSafe * 2n;
// 18014398509481982n
const subtr = multi 10n;
// 18014398509481972n
const mod = multi % 10n;
// 2n
const bigN = 2n ** 54n;
// 18014398509481984n
bigN * -1n
// 18014398509481984n
/ , , . , BigInt, , - .
:
BigInt.
const expected = 4n / 2n;
// 2n
const rounded = 5n / 2n;
// 2n, not 2.5n
BigInt Number .
0n === 0;
// false
0n == 0;
// true
1n < 2;
// true
2n > 1;
// true
2 > 2;
// false
2n > 2;
// false
2n >= 2;
// true
:
const mixed = [4n, 6, -12n, 10, 4, 0, 0n];
// [4n, 6, -12n, 10, 4, 0, 0n]
mixed.sort();
// [-12n, 0, 0n, 10, 4n, 4, 6]
, - BigInt , :
0n === Object(0n); // false
Object(0n) === Object(0n); // false
const o = Object(0n);
o === o; // true
Boolean BooleanLogical Operators ||, && !if statement.if (0n) {
console.log(" if!");
} else {
console.log(" else!");
}
// " else!"
0n || 12n;
// 12n
0n && 12n;
// 0n
Boolean(0n);
// false
Boolean(12n);
// true
!12n;
// false
!0n;
// true
BigInt.asIntN()BigInt -2width-1 2width-1-1
BigInt.asUintN()a BigInt 0 2width-1
Number BigInt , BigInt , , 253 .
JSON.stringify() BigInt TypeError, BigInt JSON , toJSON, :
BigInt.prototype.toJSON = function () {
return this.toString();
};
, JSON.stringify :
JSON.stringify(BigInt(1));
// '"1"'
// true, BigInt
function isPrime(p) {
for (let i = 2n; i * i <= p; i++) {
if (p % i === 0n) return false;
}
return true;
}
// BigInt BigInt
function nthPrime(nth) {
let maybePrime = 2n;
let prime = 0n;
while (nth >= 0n) {
if (isPrime(maybePrime)) {
nth--;
prime = maybePrime;
}
maybePrime++;
}
return prime;
}
nthPrime(20n);
// 73n
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-bigint-objects |
This page was last modified on 29 . 2026 . by MDN contributors.
BigIntObject/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |