Str = "s" ++;
Then Nan appears. Find it for a while.
The collected data is judged as follows:
1. Determine undefined:
Copy codeThe Code is as follows:
<Span style = "font-size: small;"> var tmp = undefined;
If (typeof (tmp) = "undefined "){
Alert ("undefined ");
} </Span>
Note: typeof returns a string. There are six possible types: "number", "string", "boolean", "object", "function", and "undefined"
2. null judgment:
Copy codeThe Code is as follows:
<Span style = "font-size: small;"> var tmp = null;
If (! Tmp & typeof (tmp )! = "Undefined" & tmp! = 0 ){
Alert ("null ");
} </Span>
3. Judge NaN:
Copy codeThe Code 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 its own) is false, you cannot use the = OR = Operator to determine whether a value is NaN.
Tip: The isNaN () function is usually used to check the results of parseFloat () and parseInt () to determine whether they represent valid numbers. Of course, you can also use the isNaN () function to detect arithmetic errors, such as using 0 as the divisor.
4. Determine undefined and null:
Copy codeThe Code is as follows:
<Span style = "font-size: small;"> var tmp = undefined;
If (tmp = undefined)
{
Alert ("null or undefined ");
} </Span>
Copy codeThe Code is as follows:
<Span style = "font-size: small;"> var tmp = undefined;
If (tmp = null)
{
Alert ("null or undefined ");
} </Span>
Description: null = undefined
<! -- EndFragment -->
5. Determine undefined, null, and NaN:
Copy codeThe Code is as follows:
<Span style = "font-size: small;"> var tmp = null;
If (! Tmp)
{
Alert ("null or undefined or NaN ");
} </Span>
Tip: Generally, this is enough to differentiate data.