社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
虽然es10现在还是草案,但Chrome大多数功能都已经实现。下面介绍新特性:bigint基本数据类型,es6中的基本数据类型包括:null,undefined,number,string,boolean,symbol 6种,现在增添一个新特性,可算是凑齐7兄弟了。
在javaScript中,number可以准确表达的最大数字是2^53没有比这更大的数字,
Number可以表示的最大安全范围是正负2^53 - 1。也就是Number.MAX_SAFE_INTEGER和Number.MIN_SAFE_INTEGER.BigInt类型出现就可以解决这一问题,比2^53大的数可以使用BigInt类型表示
数字后面加n。例如:123n
也可以使用BigInt()来创建一个bigint类型的数。但是不能使用new操作符,BigInt不是构造函数。
console.log(typeof 123n);
console.log(10n === BigInt(10));
console.log(10n === BigInt(10) );
console.log(10n === BigInt('10'));
console.log(10n == 10);
只能于同类型进行运算:
20n / 10n // 2
20n / 10 // Uncaught TypeError: Cannot convert a BigInt value to a number
BigInt按照与Number相同的逻辑进行装换
if(0n){
console.log(true);
}else{
console.log(false);
}
// false
Math.max(2n, 4n, 6n);// TypeError
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!