当前位置:网站首页>ES6: Expansion of Numerical Values
ES6: Expansion of Numerical Values
2022-08-11 09:20:00 【no tide】
Number.isFinite() and Number.isNaN()
ES6 provides new methods Number.isFinite() and Number.isNaN() on the Number object.
Number.isFinite()
Number .isFinite() is used to check if a number is finite, i.e. not Infinity.
Note, if the parameter type is not numeric, Number .isFinite() will always return false
Number.isFinite(15); // trueNumber.isFinite(0.8); // trueNumber.isFinite(NaN); // falseNumber.isFinite(Infinity); // falseNumber.isFinite(-Infinity); // falseNumber.isFinite('foo'); // falseNumber.isFinite('15'); // falseNumber.isFinite(true); // false
Number.isNaN()
Number.isNaN() Used to check if a value is NaN
Note: If the parameter type is not NaN
, Number.isNaN
will always beReturns false
.
Number.isNaN(NaN) // trueNumber.isNaN(15) // falseNumber.isNaN('15') // falseNumber.isNaN(true) // falseNumber.isNaN(9/NaN) // trueNumber.isNaN('true' / 0) // trueNumber.isNaN('true' / 'true') // true
Differences from traditional methods
They are the same as the traditional global methods isFinite()
and isNaN()
The difference is that the traditional method calls Number()
converts non-numeric values to numeric values,Then judge, and these two new methods are only valid for numerical values, Number.isFinite()
For non-numeric values, always return false
, Number.isNaN()
is only returned for
, not NaN
trueNaN
Always return false
.
isFinite(25) // trueisFinite("25") // trueNumber.isFinite(25) // trueNumber.isFinite("25") // falseisNaN(NaN) // trueisNaN("NaN") // trueNumber.isNaN(NaN) // trueNumber.isNaN("NaN") // falseNumber.isNaN(1) // false
Number.parseInt(), Number.parseFloat()
ES6 places the global methods parseInt()
and parseFloat()
, ported to Number
object, the behavior remains completely unchanged.
The purpose of this is to gradually reduce global methods and make the language gradually modular.
// ES5 writingparseInt('12.34') // 12parseFloat('123.45#') // 123.45// ES6 writingNumber.parseInt('12.34') // 12Number.parseFloat('123.45#') // 123.45
Number.parseInt === parseInt // trueNumber.parseFloat === parseFloat // true
If there are any mistakes in the article, I urge you to ask questions, I would greatly appreciate it.If you don't understand, you can comment and I will reply.
If the article is helpful to everyone, I hope everyone can give it a thumbs up and encouragement, and everyone will work together in the future. The road is long, and the road is long and long
边栏推荐
- 阿里云OSS上传文件超时 探测工具排查方法
- pycharm cancel msyql expression highlighting
- 基于C#通过PLCSIM ADV仿真软件实现与西门子1500PLC的S7通信方法演示
- 基于hydra库实现yaml配置文件的读取(支持命令行参数)
- HDRP Custom Pass Shader 获取世界坐标和近裁剪平面坐标
- Initial use of IDEA
- Typora和基本的Markdown语法
- Getting Started with Kotlin Algorithms Calculating Prime Factors
- 深度学习100例 —— 卷积神经网络(CNN)识别眼睛状态
- Alibaba Sentinel - Slot chain解析
猜你喜欢
随机推荐
opencv 制作趣图
idea 方法注释:自定义修改method的return和params,void不显示
持续集成/持续部署(2)Jenkins & SonarQube
IPQ4019/IPQ4029 support WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz MT7915 MT7975
Typescript基本类型---上篇
golang string manipulation
安装ES7.x集群
Oacle数据库使用问题
三次握手与四次挥手
wordpress插件开发03-简单的all in one seo 插件开发
基础SQL——DDL
《价值》读书与投资
mindspore中MindDataset读取mindrecord文件问题
MySql事务
mysql中查询多个表中的数据量
excel将数据按某一列值分组并绘制分组折线图
redis模拟面试
One network cable to transfer files between two computers
Kali penetration test environment set up
tar 命令使用