aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html
blob: cea70e68ee8464295c8fba07af3fd5b6baff3ccb (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: isFinite()
slug: Web/JavaScript/Reference/Global_Objects/isFinite
tags:
  - JavaScript
  - isFinite
translation_of: Web/JavaScript/Reference/Global_Objects/isFinite
---
<div>{{jsSidebar("Objects")}}</div>

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

<div>{{EmbedInteractiveExample("pages/js/globalprops-isfinite.html")}}</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox language-html">isFinite(<em>testValue</em>)</pre>

<h3 id="Parameters" name="Parameters">参数</h3>

<dl>
 <dt><code>testValue</code></dt>
 <dd>用于检测有限性(finiteness)的值。</dd>
</dl>

<h3 id="Description" name="Description">描述</h3>

<dl>
 <dd>isFinite 是全局的方法,不与任何对象有关系。</dd>
</dl>

<p>你可以用这个方法来判定一个数字是否是有限数字。<code>isFinite</code> 方法检测它参数的数值。如果参数是 <code>NaN</code>,正无穷大或者负无穷大,会返回<code>false</code>,其他返回 <code>true</code></p>

<h2 id="Examples" name="Examples">示例</h2>

<pre class="brush: js  language-js">isFinite(Infinity);  // false
isFinite(NaN);       // false
isFinite(-Infinity); // false

isFinite(0);         // true
isFinite(2e64);      // true, 在更强壮的Number.isFinite(null)中将会得到false


isFinite("0");       // true, 在更强壮的Number.isFinite('0')中将会得到false</pre>

<div class="line-number"> </div>

<div class="line-number"> </div>

<div class="line-number"> </div>

<div class="line-number"> </div>

<div class="line-number"> </div>

<div class="line-number"> </div>

<div class="line-number"> </div>

<div class="line-number"> </div>

<div class="line-number"> </div>

<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('ES3')}}</td>
   <td>{{Spec2('ES3')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.1.2.5', 'isFinite')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-isfinite-number', 'isFinite')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-isfinite-number', 'isFinite')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{Compat("javascript.builtins.isFinite")}}</p>

<h2 id="See_Also" name="See_Also">相关链接</h2>

<ul>
 <li>{{jsxref("Number.isFinite()")}}</li>
 <li>{{jsxref("Number.NaN()")}}</li>
 <li>{{jsxref("Number.POSITIVE_INFINITY")}}</li>
 <li>{{jsxref("Number.NEGATIVE_INFINITY")}}</li>
</ul>