当前位置:网站首页>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); // falseNumber.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') // trueDifferences 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 NaNtrueNaNAlways 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) // falseNumber.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.45Number.parseInt === parseInt // trueNumber.parseFloat === parseFloat // trueIf 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
边栏推荐
- 音视频+AI,中关村科金助力某银行探索发展新路径 | 案例研究
- canvas文字绘制(大小、粗体、倾斜、对齐、基线)
- SDUT 2877:angry_birds_again_and_again
- PowerMock for Systematic Explanation of Unit Testing
- 阿里云OSS上传文件超时 探测工具排查方法
- QTableWidget 使用方法
- The no-code platform helps Zhongshan Hospital build an "intelligent management system" to realize smart medical care
- picker选择器出现object解决办法
- 腾讯电子签开发说明
- unity shader 测试执行时间
猜你喜欢

通过Xshell连接Vagrant创建的虚拟机

HDRP shader 获取像素深度值和法线信息

基于C#通过PLCSIM ADV仿真软件实现与西门子1500PLC的S7通信方法演示

Alibaba Sentinel - Slot chain解析

三次握手与四次挥手

js将table生成excel文件并去除表格中的多余tr(js去除表格中空的tr标签)

dsu on tree(树上启发式合并)学习笔记

OAuth Client默认配置加载

IPQ4019/IPQ4029 support WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz MT7915 MT7975

WooCommerce电子商务WordPress插件-赚美国人的钱
随机推荐
CreateJS加速地址
Design of Cluster Gateway in Game Server
canvas图片操作
关于ts中的指针问题call,bind, apply
MySQL性能调优,必须掌握这一个工具!!!(1分钟系列)
基于 VIVADO 的 AM 调制解调(3)仿真验证
One network cable to transfer files between two computers
Halcon算子解释
canvas文字绘制(大小、粗体、倾斜、对齐、基线)
js将table生成excel文件并去除表格中的多余tr(js去除表格中空的tr标签)
基于consul的注册发现的微服务架构迁移到servicemesh
UNITY gameobject代码中setacvtive(false)与面板中直接去掉勾 效果不一样
关于ts的一些泛型关键字用法
游戏服务器中集群网关的设计
Song of the Cactus - Massive Rapid Expansion (1)
小程序组件不能修改ui组件样式
DataGrip配置OceanBase
Typescript基本类型---上篇
安装ES7.x集群
PowerMock for Systematic Explanation of Unit Testing