空の判定アプレット

1.未定義の分析:

var tmp = undefined; 
if (typeof(tmp) == "undefined"){ console.log("undefined"); } 

説明:文字列を返すtypeofを、6つの可能なある:「番号」、「文字列」、「ブール」、「オブジェクト」、「関数」、「未定義」と

判定はnull 2:

var tmp = null; 
if (!tmp && typeof(tmp)!="undefined" && tmp!=0){ console.log("null"); } 

3.判断NaN:

var tmp = 0/0; 
if (isNaN(tmp) ){ console.log("NaN"); } 

説明:(それ自体を含む)の任意の値の結果がそのようにNaN値かどうかを決定するために、Falseに比べ得られる、または== ===演算子を使用できない場合は不正のNaN、NaNをを示します。

ヒント:ますisNaN()関数は、一般的に、彼らは合法的な数値を表すか否かを判断するために、結果parseFloatは()とのparseInt()を検出するために使用されます。もちろん、また、0除数の場合のように、エラーカウントを検出するますisNaN()関数を使用することができます。

そして4.未定義のヌルの分析します:

var tmp = undefined; 
if (tmp== undefined) 
{ 
   console.log("null or undefined"); } var tmp = undefined; if (tmp== null) { console.log("null or undefined"); } 

説明:未定義のヌル==

5.未定義、ヌルとはNaNを分析:

var tmp = null; 
if (!tmp) 
{ 
   console.log("null or undefined or NaN"); } 

ヒント:この十分の使用に関する一般それほど区別しません。

6. nullオブジェクトの分析

かどうかを決定するために裁判官ではnull、nullに設定されたオブジェクトの始まりをしてみましょう

7.決定optionsするかどうかが

if(options){ //存在 }else{ //不存在 }

オリジナル:https://www.jianshu.com/p/ed52f2609fe6

おすすめ

転載: www.cnblogs.com/it66/p/11353959.html