aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/conflicting/web/javascript/guide/functions_925b2d10050621507a9c990cb803dcca/index.html
blob: 7d47f51efa8fb56252f6aabd05994eb789cd94bf (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
---
title: isNaN 函數
slug: conflicting/Web/JavaScript/Guide/Functions_925b2d10050621507a9c990cb803dcca
translation_of: Web/JavaScript/Guide/Functions
translation_of_original: Web/JavaScript/Guide/Obsolete_Pages/Predefined_Functions/isNaN_Function
original_slug: Web/JavaScript/Obsolete_Pages/Obsolete_Pages/Obsolete_Pages/預先定義的函數/isNaN_函數
---
<p> </p>
<div class="onlyinclude">
<h4 id="isNaN_函數">isNaN 函數</h4>
<p><code>isNaN</code> 函數對參數求值,來判斷是不是〝NaN〞(不是數字,not a number)。<code>isNaN</code> 的語句如下︰</p>
<pre>isNaN(testValue)
</pre>
<p>此處的 <code>testValue</code> 就是你想要求值的值。</p>
<p><code>parseFloat</code><code>parseInt</code> 函數會在求出來的值不是數字的時候返回〝NaN〞<span style="font-family: monospace;"></span>如果傳入的是〝NaN〞,<code>isNaN</code> 返回 true,否則為 false。</p>
<p>以下的代碼會對 <code>floatValue</code> 求值,來判斷這是不是數字,然後呼叫相應的程序︰</p>
<pre>floatValue=parseFloat(toFloat)

if (isNaN(floatValue)) {
   notFloat()
} else {
   isFloat()
}
</pre>
</div>
<p>{{ PreviousNext("Core_JavaScript_1.5_教學:預先定義的函數:isFinite_函數", "Core_JavaScript_1.5_教學:預先定義的函數:parseInt_和_parseFloat_函數") }}</p>
<p>{{ languages( { "en": "en/Core_JavaScript_1.5_Guide/Predefined_Functions/isNaN_Function", "fr": "fr/Guide_JavaScript_1.5/Fonctions_pr\u00e9d\u00e9finies/La_fonction_isNaN", "ja": "ja/Core_JavaScript_1.5_Guide/Predefined_Functions/isNaN_Function", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Funkcje_predefiniowane/Funkcja_isNaN" } ) }}</p>