JavaScript ES2021 最值得期待的 5 个新特性解析
【CSDN 编者按】ES 2021是最新版本。本次迭代中包含了已进入的第4阶段及5个新特征,让我们来一睹为快。

在写本文时,本文提到的新的 JavaScript 提案功能已进入第 4 阶段,并且几乎肯定会包含在 ES2021 中。
数字分隔符(_) 逻辑分配(&&=,||=,??=) 引用不足(WeakRef和FinalizationRegistry) Promise.any String.prototype.replaceAll
大数字文字很难使人眼快速解析,尤其是当有很多重复的数字时:
1000000000000 1019436871.42
为了提高可读性,新的 JavaScript 语言功能 启用了下划线作为数字文字中的分隔符。因此,上面的内容现在可以重写为每千位数字,例如:
1_000_000_000_000 1_019_436_871.42
现在,更容易说出第一个数字是 1 万亿,而第二个数字大约是 10 亿。
数字分隔符有助于提高各种数字文字的可读性:
// A decimal integer literal with its digits grouped per thousand:
1_000_000_000_000
// A decimal literal with its digits grouped per thousand:
1_000_000.220_720
// A binary integer literal with its bits grouped per octet:
0b01010110_00111000
// A binary integer literal with its bits grouped per nibble:
0b0101_0110_0011_1000
// A hexadecimal integer literal with its digits grouped by byte:
0x40_76_38_6A_73
// A BigInt literal with its digits grouped per thousand:
4_642_473_943_484_686_707n
它们甚至适用于八进制整数文字(尽管 我想不出 其中分隔符为此类文字提供值 的示例):
// A numeric separator in an octal integer literal: 关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 农文旅融合绘就美丽乡村新图景 7985713
- 2 超级计算机算出人类灭绝时间 7914282
- 3 130亿三岁影帝接了多少广告 7891289
- 4 春回大地农事起 春耕备耕正当时 7735036
- 5 天雷滚滚我好怕怕传到联合国 7689022
- 6 下周将迎超级大回暖 气温火箭式飙升 7589679
- 7 男生用镜头记录下女友5年的蜕变 7456634
- 8 《家有儿女》花了多少经费在餐桌上 7378652
- 9 美国将完全退出联合国?联合国回应 7296048
- 10 美将限制与中国的双向投资 中方回应 7182823