null undefined NaN

 

1. Analyzing undefined: Description: typeof returns a string, there are six possible: "number", "string", "boolean", "object", "function", "undefined"
/*
1. Analyzing undefined:
Description: typeof returns a string, there are six possibilities:
"number"、"string"、"boolean"、"object"、"function"、"undefined"
*/
var tmp=undefined;
if(typeof(tmp)=="undefined")
alert("undefined");
 
/*
2. The judgment null:
*/
was tmp = null;
if ( !tmp && typeof(tmp)!="undefined" && tmp!=0)
alert("null");
 
 
Analyzing NaN 3: Description: Results NaN if any value (including itself) are obtained compared to false, so to determine whether a value is NaN, or can not use == === operator.
/*
3. decision NaN:
 
var tmp = 0/0; if(isNaN(tmp)){ alert("NaN"); }
Note: Results NaN if any value (including itself) are obtained compared to false,
Therefore, to determine whether a value is a NaN, or can not use == === operator.
 
Tip: isNaN () function is commonly used to detect the result parseFloat () and the parseInt () to judge whether or not they represent a legitimate number. Of course, also be used isNaN () function to detect an error count, such as the case with 0 divisor.
 
 
 
And 4. Analyzing undefined null:
Description: null == undefined
*/
var tmp = undefined;
if (tmp== undefined)
alert("null or undefined");
 
var tmp = undefined;
if (tmp== null)
alert("null or undefined");
}
 
 
5. Analyzing undefined, null and NaN:
Tip: Generally not so distinguished on the use of this enough.
 
was tmp = null;
if (!tmp)
alert("null or undefined or NaN");
 
 

Guess you like

Origin www.cnblogs.com/iOS-mt/p/11077135.html
Recommended