NaN in JavaScript
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/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的更多相关文章
- 判断NaN in JavaScript
[NaN 作用是用来表示一个值不是数字] NaN在JavaScript中行为很怪异,是因为那NaN和任何值都不相等(包括它自己). NaN === NaN; // false因为 ...
- [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:正确处理Javascript特殊值---(1)正确使用NaN和Infinity
NaN时IEEE 754中定义的一个特殊的数量值.他不表示一个数字,尽管下面的表达式返回的是true typeof(NaN) === 'number' //true 该值可能会在试图将非数字形式的字符 ...
- 11 JavaScript Number原始值&对象&科学记数法&范围&进制转换&溢出Infinity&NaN
JavaScript Number对象 是经过封装的能处理数字值的对象 由Number()构造器创建 只有一种数字类型 可以使用也可以不使用小数点书写数字 JavaScript原始值与对象: 在Jav ...
- JavaScript学习笔记之数值
JavaScript内部,所有数字都是以64位浮点数形式储存,即使整数也是如此.(整数也是通过64浮点数的形式来存储的) 所以,1+1.0=2:且1===1.0的 浮点数不是精确的值,所以涉及小数的比 ...
- 对属性NaN的理解纠正和对Number.isNaN() 、isNaN()方法的辨析
1.属性NaN的误解纠正 NaN (Not a Number)在w3c 中定义的是非数字的特殊值 ,它的对象是Number ,所以并不是任何非数字类型的值都会等于NaN,只有在算术运算或数据类型转换出 ...
- 重新介绍 JavaScript
简介 为什么需要这个重新介绍呢?因为 JavaScript 已经完全可以被称为世界上被误解最严重的编程语言了.虽然它被当做玩具来用,但是藏在让人迷惑的简单表象下面的,是强大的语言特性.从2005年,一 ...
- javascript类型系统——Number数字类型
× 目录 [1]定义 [2]整数 [3]浮点数[4]科学记数[5]数值精度[6]数值范围[7]特殊数值[8]转成数值[9]实例方法 前面的话 javascript只有一个数字类型,它在内部被表示为64 ...
- JavaScript深究系列 [一]
1. JavaScript中 = = = 首先,== equality 等同,=== identity 恒等. ==, 两边值类型不同的时候,要先进行类型转换,再比较. ===,不做类型转换,类型不同 ...
随机推荐
- C++ 指针形参和指针引用形参的原理分析
C++ 函数的参数传递可以分为:值传递和引用传递. 两者的最大区别也很简单,如果该函数的参数只是读的话,值传递就可以满足.如果该函数的参数需要进行修改并返回的时候,就应该进行引用传递. C++指针作为 ...
- 51node 1134 最长递增子序列 (数据结构)
题意: 最长递增子序列 思路: 普通的$O(n^2)$的会超时.. 然后在网上找到了另一种不是dp的写法,膜拜一下,自己写了一下解释 来自:https://blog.csdn.net/Adusts/a ...
- PHP:GD库 图片水印处理
文章来源:http://www.cnblogs.com/hello-tl/p/7592974.html <?php /** * 处理图片类 * 1.添加文字水印 * 2.添加图片水印 * 3.压 ...
- POJ 1995 (快速幂) 求(A1B1+A2B2+ ... +AHBH)mod M
Description People are different. Some secretly read magazines full of interesting girls' pictures, ...
- vscode调试nodejs
1.安装nodejs 2.安装vscode 3.vscode安装debugger for chrome插件 4.新建nodejs-test文件夹,新建server.js空白文件,添加内容: var h ...
- python 中文转码 Excel读csv
大家都知道Excel读csv用的是ascii编码,我认为,ascii没有中文,所以这里指的应该是utf-8. 我遇到的问题是这样的,unity项目只能用txt文件,有一堆数据表用txt的文档保存下来了 ...
- ProxySQL Tutorial : setup in a MySQL replication topology
ProxySQL Tutorial : setup in a MySQL replication topology 时间 2015-09-15 05:23:20 ORACLE数据库技术文刊 原文 h ...
- Eclipse替换find/Replace
使用快捷键:ctrl+F replaceAll
- hdu3756(三分)
题意:三维坐标轴,有以原点为圆心,底面在xoy平面上,顶点在z轴上的圆锥,问圆锥的最小体积为多少才能完全覆盖空间里的所有点(n<=10000) 分析: 很容易想到转成二维问题,将其投影到xoz平 ...
- 创建简单的spring-mvc项目
1.第一步:创建项目 new—>Dynamic Web Project 项目创建成功后,展示如图: 2.第二步:导入springmvc的jar包和common-logging.jar 3.第三步 ...