wrote a str = "s" + +;
Then nan appeared for a while.
The information collected is as follows:
1. Judge undefined:
The code is as follows:
1 < style= "Font-size:small;" > var tmp = undefined; 2 if (typeof (tmp) = = "undefined") {3alert ("undefined"); 4 }</span>
Description: typeof returned a string of six possible types: "Number", "string", "Boolean", "Object", "function", "undefined"
2. Determine null:
1 <span style= "Font-size:small;" >varnull; 2 if typeof (TMP)! = "undefined" && tmp!=0) {3 alert ("null"); 4
3. Judge Nan:
1 < style= "Font-size:small;" > var tmp = 0/0; 2 if (IsNaN (TMP)) {3alert ("NaN"); 4 }</span>
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:
1 < style= "Font-size:small;" > var tmp = undefined; 2 if (tmp== undefined) 3 {4alert ("null or undefined"); 5 </ 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:
1 < style= "Font-size:small;" > var tmp = null; 2 if (!tmp) 3 {4alert ("null or undefined or NaN"); 5 }</span>
Tip: It is often enough to use this less differentiated.
Original link: http://www.jb51.net/article/48481.htm
The method of judging null, undefined and nan in JS