在线文档教程

isFinite

isFinite

该全局 isFinite() 函数用来判断被传入的参数值是否为一个有限数值(finite number)。在必要情况下,参数会首先转为一个数值。

语法

isFinite(testValue)

参数

testValue用于检测有限性(finiteness)的值。

返回值

false如果参数为正的或负的InfinityNaN; 否则,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")

规范

SpecificationStatusComment
ECMAScript 3rd Edition (ECMA-262)StandardInitial 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

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)

FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)