I wrote str ="s" ;
Then Nan appeared and I searched for it for a while.
Collect the information and judge as follows:
1. Judge undefined:
var tmp = undefined;
if (typeof(tmp) == "undefined"){
alert("undefined");
}
Explanation: typeof returns a string, there are six possibilities: "number", "string", "boolean", "object", "function ", "undefined"
2. Determine null:
var tmp = null;
if (!tmp && typeof(tmp)!="undefined" && tmp!=0){
alert( "null");
}
3. Determine NaN:
var tmp = 0/0;
if(isNaN(tmp)){
alert("NaN");
}
Explanation: If NaN is compared with any value (including itself), the result will be false, so To determine whether a value is NaN, you cannot use the == or === operators.
Tip: The isNaN() function is usually used to detect the results of parseFloat() and parseInt() to determine whether they represent legal numbers. Of course, you can also use the isNaN() function to detect arithmetic errors, such as using 0 as a divisor.
4. Judge undefined and null:
< span style="font-size: small;">var tmp = undefined;
if (tmp== undefined)
{
alert("null or undefined");
} < /span>
var tmp = undefined;
if (tmp== null)
{
alert("null or undefined");
} span>
Explanation: null==undefined
5. Judge undefined, null and NaN:
var tmp = null;
if (!tmp)
{
alert("null or undefined or NaN");
}
Tip: Generally not so distinguishable Just use this.