blob: 7d8e6cb3c49fbc3f39ef07bc08529bcf54d5b12b (
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
|
---
title: Infinity
slug: Web/JavaScript/Reference/Global_Objects/Infinity
tags:
- JavaScript
translation_of: Web/JavaScript/Reference/Global_Objects/Infinity
---
<div>{{jsSidebar("Objects")}}</div>
<p>全局属性 <code><strong>Infinity</strong></code> 是一个数值,表示无穷大。</p>
<p>{{js_property_attributes(0,0,0)}}</p>
<p>{{EmbedInteractiveExample("pages/js/globalprops-infinity.html")}}</p>
<h2 id="Description" name="Description">描述</h2>
<p><code>Infinity</code> 是<em>全局对象</em>(<em>global object</em>)的一个属性,即它是一个全局变量。</p>
<p><code>Infinity</code> 的初始值是 {{jsxref("Number.POSITIVE_INFINITY")}}。<code>Infinity</code>(正无穷大)大于任何值。</p>
<p>该值的意义与数学无穷大略有不同。 有关详细信息,请参见{{jsxref("Number.POSITIVE_INFINITY")}}。</p>
<p>在 ECMAScript 5 的规范中, <code>Infinity</code> 是只读的(实现于 JavaScript 1.8.5 / Firefox 4)。</p>
<h2 id="示例">示例</h2>
<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">Infinity</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* Infinity */</span>
console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">Infinity</span> <span class="operator token">+</span> <span class="number token">1</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* Infinity */</span>
console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">pow</span><span class="punctuation token">(</span><span class="number token">10</span><span class="punctuation token">,</span> <span class="number token">1000</span><span class="punctuation token">)</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* Infinity */</span>
console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">0</span><span class="punctuation token">)</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* -Infinity */</span>
console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">1</span> <span class="operator token">/</span> <span class="number token">Infinity</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* 0 */</span></code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-value-properties-of-the-global-object-infinity', 'Infinity')}}</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("javascript.builtins.Infinity")}}</p>
<h2 id="相关链接">相关链接</h2>
<ul>
<li>{{jsxref("Number.NEGATIVE_INFINITY")}}</li>
<li>{{jsxref("Number.POSITIVE_INFINITY")}}</li>
<li>{{jsxref("Number.isFinite")}}</li>
</ul>
|