wrote a str = "s" + +;
Then nan appeared for a while.
The information collected is as follows:
1. Judge undefined:
?
| 1234 |
vartmp = undefined; if(typeof(tmp) == "undefined"){ alert("undefined"); } |
Description: typeof returned a string of six possible types: "Number", "string", "Boolean", "Object", "function", "undefined"
2. Determine null:
?
| 1234 |
vartmp = null; if (!tmp && typeof(tmp)!="undefined"&& tmp!=0){ alert("null"); } |
3. Judge Nan:
?
| 1234 |
vartmp = 0/0; if(isNaN(tmp)){ alert("NaN"); } |
Note: If you compare Nan to any value (including itself), the result is false, so to determine whether a value is Nan, you cannot use the = = or = = = operator.
Tip: the IsNaN () function is often used to detect the results of parsefloat () and parseint () to determine whether they represent a valid number. Of course, you can also use the IsNaN () function to detect arithmetic errors, such as using 0 to divide the case.
4. Judge undefined and null:
?
| 12345 |
vartmp = undefined; if(tmp== undefined) { alert("null or undefined"); } |
?
| 12345 |
vartmp = undefined; if(tmp== null) { alert("null or undefined"); } |
Description: null==undefined
<!--endfragment-->
5. Judge undefined, null, and Nan:
?
| 12345 |
vartmp = null; if(!tmp) { alert("null or undefined or NaN"); } |
Tip: It is often enough to use this less differentiated.
The method of judging null, undefined and nan in JS