blob: a15d29c7c00f599f03c1522c69cf4760d61da8fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
---
title: Number.isFinite()
slug: Web/JavaScript/Reference/Global_Objects/Number/isFinite
tags:
- JavaScript
- Method
- Number
- Reference
translation_of: Web/JavaScript/Reference/Global_Objects/Number/isFinite
---
<div>{{JSRef}}</div>
<p><strong><code>Number.isFinite()</code></strong> 方法會判斷傳入的值是否為有限數(finite number)。</p>
<div>{{EmbedInteractiveExample("pages/js/number-isfinite.html")}}</div>
<h2 id="語法">語法</h2>
<pre class="syntaxbox">Number.isFinite(v<var>alue</var>)</pre>
<h3 id="參數">參數</h3>
<dl>
<dt><code>value</code></dt>
<dd>The value to be tested for finiteness.</dd>
</dl>
<h3 id="回傳值">回傳值</h3>
<p>A {{jsxref("Boolean")}} indicating whether or not the given value is a finite number.</p>
<h2 id="說明">說明</h2>
<p>In comparison to the global {{jsxref("isFinite", "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 <code>true</code>.</p>
<h2 id="範例">範例</h2>
<pre class="brush: js">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)
</pre>
<h2 id="Polyfill">Polyfill</h2>
<pre class="brush: js">Number.isFinite = Number.isFinite || function(value) {
return typeof value === 'number' && isFinite(value);
}
</pre>
<h2 id="規範">規範</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-number.isfinite', 'Number.isInteger')}}</td>
<td>{{Spec2('ES6')}}</td>
<td>Initial definition.</td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-number.isfinite', 'Number.isInteger')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("javascript.builtins.Number.isFinite")}}</p>
<h2 id="參見">參見</h2>
<ul>
<li>The {{jsxref("Number")}} object it belongs to.</li>
<li>The global function {{jsxref("isFinite")}}.</li>
</ul>
|