JS基本数据类型——BigInt
1 //大整型 2 let n = 520n;//他只用在普通整型后边添加一个n就可以了 3 console.log(n,typeof(n));
可以将普通整数值转化为大整型的值。
1 //函数 2 let n = 123; 3 console.log(BigInt(n)); 4 //不能使用浮点数进行转换 5 console.log(BigInt(0.2));
1 let max = Number.MAX_SAFE_INTEGER;//Number的最大安全整数 2 console.log(max); 3 console.log(max + 1); 4 //超过number的最大数值范围,运算就会出错 5 console.log(max + 2); 6 7 console.log(BigInt(max)); 8 //BigInt数据类型不能直接和普通数据类型进行运算 9 console.log(BigInt(max) + BigInt(1)); 10 console.log(BigInt(max) + BigInt(2));