isFinite
isFinite
该全局 isFinite() 函数用来判断被传入的参数值是否为一个有限数值(finite number)。在必要情况下,参数会首先转为一个数值。
语法
isFinite(testValue)
参数
testValue
用于检测有限性(finiteness)的值。
返回值
false
如果参数为正的或负的Infinity
或NaN
; 否则,true
。
描述
isFinite 是全局的方法,不与任何对象有关系。
你可以用这个方法来判定一个数字是否是有限数字。isFinite
方法检测它参数的数值。如果参数是NaN
,正无穷大或者负无穷大,会返回false
,其他返回true
。
示例
isFinite(Infinity // false
isFinite(NaN // false
isFinite(-Infinity // false
isFinite(0 // true
isFinite(2e64 // true
isFinite(910 // true
isFinite(null // true, would've been false with the
// more robust Number.isFinite(null)
isFinite('0' // true, would've been false with the
// more robust Number.isFinite("0")
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262)The definition of 'isFinite' in that specification. | Standard | |
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'isFinite' in that specification. | Standard | |
ECMAScript Latest Draft (ECMA-262)The definition of 'isFinite' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |