I wrote a str ="s"++;
Then Nan appeared and looked for it for a while.
The data is collected as follows:
1.Judge undefined:
The code copy is as follows:
<span style="font-size: small;">var tmp = undefined;
if (typeof(tmp) == "undefined"){
alert("undefined");
}</span>
Description: typeof returns a string, and there are six possibilities: "number", "string", "boolean", "object", "function", "undefined"
2.Judge null:
The code copy is as follows:
<span style="font-size: small;">var tmp = null;
if (!tmp && typeof(tmp)!="undefined" && tmp!=0){
alert("null");
} </span>
3.Judge NaN:
The code copy is as follows:
<span style="font-size: small;">var tmp = 0/0;
if(isNaN(tmp)){
alert("NaN");
}</span>
Note: If the result of comparing NaN with any value (including itself) is false, so to determine whether a value is NaN, the == or === operator cannot be used.
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:
The code copy is as follows:
<span style="font-size: small;">var tmp = undefined;
if (tmp== undefined)
{
alert("null or undefined");
} </span>
The code copy is as follows:
<span style="font-size: small;">var tmp = undefined;
if (tmp== null)
{
alert("null or undefined");
}</span>
Description: null==undefined
<!--EndFragment-->
5.Judge undefined, null and NaN:
The code copy is as follows:
<span style="font-size: small;">var tmp = null;
if (!tmp)
{
alert("null or undefined or NaN");
}</span>
Tip: Generally, if you don’t distinguish it so much, use this enough.