Number.isFinite()
Number.isFinite()
静态方法确定传递的值是否是有限数 - 也就是说,它检查给定值是否是一个数字,并且该数字既不是正 Infinity
,负 Infinity
,也不是 NaN
。
¥The Number.isFinite()
static method determines whether the passed value is a finite number — that is, it checks that a given value is a number, and the number is neither positive Infinity
, negative Infinity
, nor NaN
.
Try it
语法
参数
返回值
示例
使用 isFinite()
Number.isFinite() 和全局 isFinite() 之间的区别
¥Difference between Number.isFinite() and global isFinite()
与全局 isFinite()
函数相比,此方法不会首先将参数转换为数字。这意味着只有 number 和 类型的值是有限返回 true
,非数字总是返回 false
。
¥In comparison to the global isFinite()
function, this method doesn't first convert the parameter to a number. This means only values of the type number and are finite return true
, and non-numbers always return false
.
js
isFinite("0"); // true; coerced to number 0
Number.isFinite("0"); // false
isFinite(null); // true; coerced to number 0
Number.isFinite(null); // false
规范
Specification |
---|
ECMAScript Language Specification # sec-number.isfinite |
浏览器兼容性
BCD tables only load in the browser