Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

isFinite()

BaselineWidely available

TheisFinite() function determines whether a value is finite, first converting the value to a number if necessary. A finite number is one that's notNaN or ±Infinity. Because coercion inside theisFinite() function can besurprising, you may prefer to useNumber.isFinite().

Try it

function div(x) {  if (isFinite(1000 / x)) {    return "Number is NOT Infinity.";  }  return "Number is Infinity!";}console.log(div(0));// Expected output: "Number is Infinity!""console.log(div(1));// Expected output: "Number is NOT Infinity."

Syntax

js
isFinite(value)

Parameters

value

The value to be tested.

Return value

false if the given value isNaN,Infinity, or-Infinity after beingconverted to a number; otherwise,true.

Description

isFinite() is a function property of the global object.

When the argument to theisFinite() function is not of typeNumber, the value is first coerced to a number, and the resulting value is then compared againstNaN and ±Infinity. This is as confusing as the behavior ofisNaN — for example,isFinite("1") istrue.

Number.isFinite() is a more reliable way to test whether a value is a finite number value, because it returnsfalse for any non-number input.

Examples

Using isFinite()

js
isFinite(Infinity); // falseisFinite(NaN); // falseisFinite(-Infinity); // falseisFinite(0); // trueisFinite(2e64); // trueisFinite(910); // true// Would've been false with the more robust Number.isFinite():isFinite(null); // trueisFinite("0"); // true

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-isfinite-number

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp