当前位置:网站首页>ES11新增数据类型BigInt大整型
ES11新增数据类型BigInt大整型
2022-08-11 05:17:00 【前端小马】
bigint使用方式:
1.直接添加字母n
var num=100n;
console.log(typeof num)//bigint
2.使用bigint函数
var num=100;
console.log(typeof BigInt(num))//bigint
注意:
1. 小数不能转为bigint类型
var num=100.1;
console.log(BigInt(num))//报错
2. bigint类型只能与bigint类型做运算
var num=100
console.log(BigInt(num)+1)//报错为了计算的准确性,js定义了最大安全整数,这个整数是
let max=Number.MAX_SAFE_INTEGER
console.log(max)//9007199254740991在最大安全值得基础上不断+1计算就会出错
let max=Number.MAX_SAFE_INTEGER
console.log(max)//9007199254740991
console.log(max+1)//9007199254740992 正确
console.log(max+2)//9007199254740992 错误
console.log(max+4)//9007199254740996 错误而用bigInt()方法将数转成大整型就能解决这个问题
let max=Number.MAX_SAFE_INTEGER
console.log(BigInt(max))//9007199254740991n
console.log(BigInt(max)+BigInt(1))//9007199254740992n 正确
console.log(BigInt(max)+BigInt(2))//9007199254740993n 正确
console.log(BigInt(max)+BigInt(4))//9007199254740995n 正确
边栏推荐
- flaks框架学习:在 URL 中添加变量
- 深入理解线程、进程、多线程、线程池
- (2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
- 吃瓜教程task05 第6章 支持向量机
- [C language advanced] The first in-depth analysis of the storage of integer data in memory (1)
- 【记录】TypeScript
- 2021研究生数学建模D题,BP神经网络和卷积神经网络解题代码(基于pytorch)
- leetcode21.合并两个有序链表
- 第4章 复合类型-2(指针)
- 一张图带你解读--如何从零开始学习接口自动化
猜你喜欢
随机推荐
lspci 命令使用
Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe
Chapter 13 Class Inheritance-1
04-开发自己的npm包及发布流程详细讲解
RK3399上的Tengine实践笔记
设计三级联动
[C language advanced] The first in-depth analysis of the storage of integer data in memory (1)
task04 Pytorch进阶训练技巧
(1) Docker installs Redis in practice (one master, two slaves, three sentinels)
C语言结构体——位段概念的讲解
CSDN 社区内容创作规范
gradle-wrapper.jar description
flaks框架学习:在 URL 中添加变量
labelme工具,对类别标注,再进行细致的分割
pytorch中tensor 生成的函数
selenuim使用cookie登录京东
(3) How Redis performs stress testing
Chapter 5 Loops and Relational Expressions
ClionIDE通过指定编译器编译
Install different versions of MinGW (g++/gcc) and the configuration of the corresponding clion editor under Win









