Number.isFinite() method determines whether the passed value is a finite number.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

句法

Number.isFinite(value)
					

参数

value

The value to be tested for finiteness.

返回值

A 布尔 indicating whether or not the given value is a finite number.

描述

In comparison to the global isFinite() function, this method doesn't forcibly convert the parameter to a number. This means only values of the type number, that are also finite, return true .

Polyfill

if (Number.isFinite === undefined) Number.isFinite = function(value) {
    return typeof value === 'number' && isFinite(value);
}
					

范例

Using isFinite

Number.isFinite(Infinity);  // false
Number.isFinite(NaN);       // false
Number.isFinite(-Infinity); // false
Number.isFinite(0);         // true
Number.isFinite(2e64);      // true
Number.isFinite('0');       // false, would've been true with
                            // global isFinite('0')
Number.isFinite(null);      // false, would've been true with
                            // global isFinite(null)
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'Number.isInteger' in that specification.

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
isFinite Chrome 19 Edge 12 Firefox 16 IE No Opera 15 Safari 9 WebView Android ≤37 Chrome Android 25 Firefox Android 16 Opera Android 14 Safari iOS 9 Samsung Internet Android 1.5 nodejs 0.10

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: