mozilla

Revision 447181 of Number.isFinite()

  • Revision slug: JavaScript/Reference/Global_Objects/Number/isFinite
  • Revision title: Number.isFinite
  • Revision id: 447181
  • Created:
  • Creator: zhangyaochun1987
  • Is current revision? No
  • Comment share for Chinese

Revision Content

{{fx_minversion_header("16") }}

概述

判定指定的参数是否是有限的。比全局方法 isFinite 要更好。

Method of Number
Implemented in JavaScript 1.8.5+
ECMAScript Edition ECMAScript 6th Edition

语法

Number.isFinite(testValue);

参数

testValue
检测这个值是否是有限的

描述

和全局的 isFinite 方法相比,这个方法不会强制把参数转换为数值。这意味着只有数值类型的值,还有finite返回true

 

示例

Number.isFinite(Infinity);  // false
Number.isFinite(NaN);       // false
Number.isFinite(-Infinity); // false

// all other numbers true
Number.isFinite(0);
Number.isFinite(2e64); 

// everything else is false
Number.isFinite("0");       // false, would've been true with global isFinite

Revision Source

<div>
  {{fx_minversion_header("16") }}</div>
<h2 id="Summary">概述</h2>
<p>判定指定的参数是否是有限的。比全局方法&nbsp;<code style="line-height: inherit; font-size: 14px;"><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite" style="line-height: inherit;">isFinite</a>&nbsp;要更好。</code></p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Method of <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number"><code>Number</code></a></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Implemented in</td>
      <td>JavaScript 1.8.5+</td>
    </tr>
    <tr>
      <td>ECMAScript Edition</td>
      <td>ECMAScript 6th Edition</td>
    </tr>
  </tbody>
</table>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox">
<code>Number.isFinite(test<em>Value</em>);</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
  <dt>
    <code>test<em>Value</em></code></dt>
  <dd>
    检测这个值是否是有限的</dd>
</dl>
<h2 id="Description">描述</h2>
<p>和全局的&nbsp;<code style="line-height: inherit; font-size: 14px;"><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite" style="line-height: inherit;">isFinite</a>&nbsp;方法相比,这个方法不会强制把参数转换为数值。这意味着只有数值类型的值,还有finite返回true</code></p>
<p>&nbsp;</p>
<h2 id="Examples">示例</h2>
<pre class="brush:js;">
Number.isFinite(Infinity);  // false
Number.isFinite(NaN);       // false
Number.isFinite(-Infinity); // false

// all other numbers true
Number.isFinite(0);
Number.isFinite(2e64); 

// everything else is false
Number.isFinite("0");       // false, would've been true with global isFinite
</pre>
Revert to this revision