wrote a str = "s" + +;
Then there was Nan, and for a while.
The information collected is as follows:
1. Judge undefined:
Copy Code code as follows:
<span style= "Font-size:small;" >var tmp = undefined;
if (typeof (tmp) = = "undefined") {
Alert ("undefined");
}</span>
Description: TypeOf returns a string of six possible: "Number", "string", "Boolean", "Object", "function", "undefined"
2. Null judgement:
Copy Code code as follows:
<span style= "Font-size:small;" >var tmp = NULL;
if (!tmp && typeof (TMP)!= "undefined" && tmp!=0) {
Alert ("null");
} </span>
3. Judge Nan:
Copy Code code as follows:
<span style= "Font-size:small;" >var tmp = 0/0;
if (isNaN (TMP)) {
Alert ("NaN");
}</span>
Note: If the result of Nan being compared to any value (including itself) is false, you cannot use the = = or = = operator to determine whether a value is NaN.
Tip: the isNaN () function is commonly used to detect the results of parsefloat () and parseint () to determine whether they represent legitimate numbers. Of course, you can also use the isNaN () function to detect arithmetic errors, such as the case of dividing by 0.
4. Judge undefined and null:
Copy Code code as follows:
<span style= "Font-size:small;" >var tmp = undefined;
if (tmp== undefined)
{
Alert ("null or undefined");
} </span>
Copy Code code 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:
Copy Code code as follows:
<span style= "Font-size:small;" >var tmp = NULL;
if (!tmp)
{
Alert ("null or undefined or NaN");
}</span>
Tip: Generally not so differentiated on the use of this enough.