isFinite()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itโs been available across browsers since โจ2015๋ 7์โฉ.
isFinite() ์ ์ญ ํจ์๋ ์ฃผ์ด์ง ๊ฐ์ด ์ ํ์์ธ์ง ํ๋ณํฉ๋๋ค. ํ์ํ ๊ฒฝ์ฐ ๋งค๊ฐ๋ณ์๋ฅผ ๋จผ์ ์ซ์๋ก ๋ณํํฉ๋๋ค.
์๋ํด ๋ณด๊ธฐ
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."
๊ตฌ๋ฌธ
isFinite(testValue);
๋งค๊ฐ๋ณ์
testValue-
์ ํํ์ง ํ๋ณํ ๊ฐ.
๋ฐํ ๊ฐ
testValue๊ฐ ์ ๋๋ ์์ Infinity, NaN, ๋๋ undefined๋ฉด false, ์๋๋ฉด true.
์ค๋ช
isFinite()์ ์ต์์ ํจ์๋ก ์ด๋ค ๊ฐ์ฒด์๋ ์ฐ๊ฒฐ๋์ง ์์์ต๋๋ค.
์ซ์๊ฐ ์ ํ์์ธ์ง ํ๋ณํ๊ธฐ ์ํด isFinite()์ ์ฌ์ฉํ ์ ์์ต๋๋ค. isFinite()์ ์ฃผ์ด์ง ์๋ฅผ ๊ฒ์ฌํด ๊ทธ ๊ฐ์ด NaN, ์์ ๋ฌดํ๋, ๋๋ ์์ ๋ฌดํ๋์ด๋ฉด false๋ฅผ ๋ฐํํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด true๋ฅผ ๋ฐํํฉ๋๋ค.
์์
>isFinite() ์ฌ์ฉํ๊ธฐ
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 |
|---|
| ECMAScriptยฎ 2026 Languageย Specification> # sec-isfinite-number> |