| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/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 9.
BigInt Number 2^53 - 1 .
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
BigInt Number . BigInt Math , Number . . , BigInt Number .
BigInt typeof "bigint".
typeof 1n === "bigint"; // true
typeof BigInt("1") === "bigint"; // true
Object BigInt object .
typeof Object(1n) === "object"; // true
+, *, -, **, % BigInt BigInt . , BigInt >>> ( ) . asm.js , + .
const previousMaxSafe = BigInt(Number.MAX_SAFE_INTEGER);
// 9007199254740991
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
/ . BigInt BigDecimal , . , .
:
BigInt .
const expected = 4n / 2n;
// 2n
const rounded = 5n / 2n;
// 2.5n 2n
BigInt Number .
0n === 0;
// false
0n == 0;
// true
Number BigInt .
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]
Object BigInt .
0n === Object(0n); // false
Object(0n) === Object(0n); // false
const o = Object(0n);
o === o; // true
BigInt Number .
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()BigInt .
BigInt.asIntN() BigInt -2^(width - 1) 2^(width - 1) - 1 .
BigInt.asUintN() BigInt 0 2^width - 1 .
BigInt.prototype.toLocaleString()BigInt . Object.prototype.toLocaleString() .
BigInt.prototype.toString()BigInt . Object.prototype.toString() .
BigInt.prototype.valueOf()BigInt . Object.prototype.valueOf() .
BigInt Number , 2^53 BigInt .
BigInt , JSON.stringify() BigInt TypeError . , toJSON .
BigInt.prototype.toJSON = function () {
return this.toString();
};
.
JSON.stringify(BigInt(1));
// '"1"'
// BigInt true
function isPrime(p) {
for (let i = 2n; i * i <= p; i++) {
if (p % i === 0n) return false;
}
return true;
}
// BigInt , n BigInt
function nthPrime(nth) {
let maybePrime = 2n;
let prime = 0n;
while (nth >= 0n) {
if (isPrime(maybePrime)) {
nth -= 1n;
prime = maybePrime;
}
maybePrime += 1n;
}
return prime;
}
nthPrime(20n);
// 73n
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-bigint-objects |
This page was last modified on 2024 12 17 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 |