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) }

NaN in JavaScript的更多相关文章

  1. 判断NaN in JavaScript

    [NaN 作用是用来表示一个值不是数字] NaN在JavaScript中行为很怪异,是因为那NaN和任何值都不相等(包括它自己).            NaN === NaN; // false因为 ...

  2. [Javascript] Identify and Deal with NaN in JavaScript

    Dealing with the special NaN value can be tricky in JavaScript. It behaves like a number and not a n ...

  3. 建议3:正确处理Javascript特殊值---(1)正确使用NaN和Infinity

    NaN时IEEE 754中定义的一个特殊的数量值.他不表示一个数字,尽管下面的表达式返回的是true typeof(NaN) === 'number' //true 该值可能会在试图将非数字形式的字符 ...

  4. 11 JavaScript Number原始值&对象&科学记数法&范围&进制转换&溢出Infinity&NaN

    JavaScript Number对象 是经过封装的能处理数字值的对象 由Number()构造器创建 只有一种数字类型 可以使用也可以不使用小数点书写数字 JavaScript原始值与对象: 在Jav ...

  5. JavaScript学习笔记之数值

    JavaScript内部,所有数字都是以64位浮点数形式储存,即使整数也是如此.(整数也是通过64浮点数的形式来存储的) 所以,1+1.0=2:且1===1.0的 浮点数不是精确的值,所以涉及小数的比 ...

  6. 对属性NaN的理解纠正和对Number.isNaN() 、isNaN()方法的辨析

    1.属性NaN的误解纠正 NaN (Not a Number)在w3c 中定义的是非数字的特殊值 ,它的对象是Number ,所以并不是任何非数字类型的值都会等于NaN,只有在算术运算或数据类型转换出 ...

  7. 重新介绍 JavaScript

    简介 为什么需要这个重新介绍呢?因为 JavaScript 已经完全可以被称为世界上被误解最严重的编程语言了.虽然它被当做玩具来用,但是藏在让人迷惑的简单表象下面的,是强大的语言特性.从2005年,一 ...

  8. javascript类型系统——Number数字类型

    × 目录 [1]定义 [2]整数 [3]浮点数[4]科学记数[5]数值精度[6]数值范围[7]特殊数值[8]转成数值[9]实例方法 前面的话 javascript只有一个数字类型,它在内部被表示为64 ...

  9. JavaScript深究系列 [一]

    1. JavaScript中 = = = 首先,== equality 等同,=== identity 恒等. ==, 两边值类型不同的时候,要先进行类型转换,再比较. ===,不做类型转换,类型不同 ...

随机推荐

  1. thinkphp 5.0整合阿里大于验证码短信发送接口,含完整模型验证实例DEMO

    为大家分享一个阿里大于短信发送接口: 首先创建一个发送模型(Send.php): <?php namespace app\index\model; use think\Validate; cla ...

  2. Python 面向对象 组合-多态与多态性-封装-property

    面向对象-组合 1.什么是组合 组合指的是某一个对象拥有一个属性,该属性的值是另外一个类的对象 class Foo: xxx = 111 class Bar: yyy = 222 obj = Foo( ...

  3. Linux命令整理(2018/9/9-2018/9/15)

    根据本周的Linux学习进度,整理了部分Linux知识及常用命令,待完善…… 1.显示默认启动方式(默认启动目标): systemctl get-default 2.设置默认启动方式(默认启动目标): ...

  4. 树莓派 -- oled 续(1) wiringPi

    在上文中,分析了wiringPi 的oled demo是使用devfs来控制spi master和spi slave通讯. https://blog.csdn.net/feiwatson/articl ...

  5. POJ3641 (快速幂) 判断a^p = a (mod p)是否成立

    Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...

  6. Vertex&Frag

    一.Vertex&Frag 包含Vertex&Fragment 的Shader叫做顶点&像素着色器,在Vertex的功能函数中,我们侧重于几何计算,如纹理坐标,顶点坐标等:在F ...

  7. vim学习之旅01-文本搜索并高亮显示

    step 1:在linux终端新建一个test.txt文本文档:vim test.txt; 回车后打开编辑器: step 2:进入编辑状态(键盘"i")输入一段文本,退出编辑(键盘 ...

  8. CSU 1214 找最大异或值

    题目大意: 给定一堆数,从中找2个数异或得到的最大值 直接暴力会超时,我们要考虑对于每一个数去匹配找到异或的最大值,我们希望2进制越前面的数尽可能都为1 所以我们用 0-1 字典树保存这些数,因为一个 ...

  9. noip模拟赛 写代码

    分析:这其实就是括号匹配题,一眼贪心题,不过一开始贪错了,以为([)]是合法的......其实括号之间不能嵌套. 一开始的想法是尽量往左边填左括号,因为每种括号的数量都确定了,那么左括号和右括号的数量 ...

  10. Redis事务【十二】

    一.概述: 和众多其它数据库一样,Redis作为NoSQL数据库也同样提供了事务机制.在Redis中,MULTI/EXEC/DISCARD/WATCH这四个命令是我们实现事务的基石.相信对有关系型数据 ...