BigInt大整数

BigInt大整数

能表示的范围更大

let number = 121n
console.log(typeof number);  //bigint

let a = 123
console.log(BigInt(a));  //123n,将普通的数转换为大整数

let max = Number.MAX_SAFE_INTEGER
console.log(max);  //9007199254740991
console.log(max+1);  //9007199254740992
console.log(max+2);  //9007199254740992

console.log(BigInt(max));  //9007199254740991n
console.log(BigInt(max)+1n);  //9007199254740992n
console.log(BigInt(max)+2n);  //9007199254740993n
// 注意,BigInt 类型不能和普通的类型直接运算。还有,如果你直接在括号里面加,那么它也会受到那个最大安全整数的限制
posted @ 2022-07-13 14:34  朱在春  阅读(43)  评论(0编辑  收藏  举报