https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN

The global NaN property is a value representing Not-A-Number.

NaN is a property of the global object.

The initial value of NaN is Not-A-Number — the same as the value of Number.NaN.

In modern browsers, NaN is a non-configurable, non-writable property.

Even when this is not the case, avoid overriding it.

It is rather rare to use NaN in a program.

It is the returned value when Math functions fail (Math.sqrt(-1)) or when a function trying to parse a number fails (parseInt("blabla")).

Testing against NaN

NaN compares unequal (via ==, !=, ===, and !==) to any other value -- including to another NaN value.

Use Number.isNaN() or isNaN() to most clearly determine whether a value is NaN.

Or perform a self-comparison: NaN, and only NaN, will compare unequal to itself.

NaN === NaN;        // false
Number.NaN === NaN; // false
isNaN(NaN); // true
isNaN(Number.NaN); // true function valueIsNaN(v) { return v !== v; }
valueIsNaN(1); // false
valueIsNaN(NaN); // true
valueIsNaN(Number.NaN); // true

However, do note the difference between isNaN() and Number.isNaN(): the former will return true if the value is currently NaN, or if it is going to be NaN after it is coerced to a number, while the latter will return true only if the value is currently NaN:

isNaN('hello world'); // returns 'true'.
Number.isNaN('hello world'); // returns 'false'.

判断一个参数是否是数字

https://www.codewars.com/kata/is-it-a-number/train/javascript

https://stackoverflow.com/questions/18082/validate-decimal-numbers-in-javascript-isnumeric

https://stackoverflow.com/questions/6449611/how-to-check-whether-a-value-is-a-number-in-javascript-or-jquery

https://stackoverflow.com/questions/1303646/check-whether-variable-is-number-or-string-in-javascript

function isDigit(s) {
return !isNaN(parseFloat(s)) && isFinite(s);
}

或者是

function isDigit(s) {
return s==(parseFloat(s)) ;
}

或者是

function isNumber(n) { return !isNaN(parseFloat(n)) && !isNaN(n - 0) }

最新文章

  1. MongoDB(四)mongodb设置用户访问权限
  2. CAP定理
  3. windows下安装 sphinx 数据库全文搜索引擎
  4. 使用SBT构建Scala应用(转自git)
  5. Nhibernate中 Many-To-One 中lazy="proxy" 延迟不起作用的原因
  6. React-Native错误笔记-EPERM
  7. Visual Studio C++ Command Line
  8. WPF中添加Ribbon遇到的问题
  9. github 的分支操作
  10. hdu2102(bfs)
  11. 浅谈 angular新旧版本问题
  12. hibernate 多对多关系总结
  13. Day3---------Linux操作系统
  14. javaScript设计模式之面向对象编程(object-oriented programming,OOP)--寄生组合式继承
  15. table动态增加删除
  16. java的TCP和UDP编程
  17. ABP框架系列之四十八:(Specifications-规范)
  18. 清理sqlserver 2012 日志文件
  19. C++:派生类的构造函数和析构函数的调用顺序
  20. 安装PyInstaller打包python

热门文章

  1. HTML 之 DOM文件对象模型
  2. [bzoj2806][Ctsc2012]Cheat(后缀自动机(SAM)+二分答案+单调队列优化dp)
  3. 笔试算法题(09):查找指定和值的两个数 & 构造BST镜像树
  4. 在前后端分离的SpringBoot项目中集成Shiro权限框架
  5. 树莓派 -- oled
  6. PHP程序员必须知道的两种日志
  7. scrapy快速入门
  8. 19-看图理解数据结构与算法系列(Radix树)
  9. Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案
  10. CentOS7 Firewall防火墙配置用法详解