1. Judge whether each other is equal
function Btnclick () {alert (null = = NULL);//true alert (undefined==undefined);//true alert (Nan==nan);//false}
Summarize:
(1) Two null is equal
(2) Two undefined are equal
(3) Two Nan is unequal
function Btnclick () {alert (null = = undefined),//true alert (null = = = undefined),//false alert (null = = NaN);//false alert (undefined = = NaN);//false}
Summarize:
(1) null and undefined are equal by using "= =", while "= = =" is not equal
(2) null and Nan are not equal
(3) undefined and Nan are not equal
function Btnclick () {alert (typeof (null));//object alert (typeof (undefined));//undefined}
Summarize:
(1) The result of typeof (null) is "Object"
(2) The result of typeof (undefined) is "undefined"
2. Determine if null, undefined, NaN
Use = =, = = =, isxxx, typeof, Instanceof
2.1. Judge whether it is undefined
the right approach :
var tmp = Undefined;function Btnclick () {if (typeof (tmp) = = = "undefined") {alert ("TMP is undefined!"); }}
Or
var tmp = NULL; function Btnclick () {if (tmp = = = undefined) {alert ("TMP is undefined!"); }}
the wrong approach :
var tmp = undefined; Null,undefinedfunction Btnclick () {if (tmp = = undefined) {alert ("TMP is undefined!"); }}
Analysis: If you use tmp==undefined, the value of TMP will be determined to be true regardless of whether it is null or undefined.
2.2. Determine if NULL
the right approach :
var tmp = NULL; Null,nan,undefinedfunction Btnclick () {if (!tmp && typeof (TMP)! = "undefined" &&!isnan (tmp)) {A Lert ("TMP is null!"); }}
Or
var tmp = NULL; Null,nan,undefinedfunction Btnclick () {if (Tmp==null && typeof (TMP)! = "undefined") {alert ("TMP is null! "); }}
2.3. Determine if it is Nan
The right approach:
var tmp = NaN; Null,nan,undefinedfunction Btnclick () {if (IsNaN (TMP) && typeof (TMP)! = "undefined") {alert ("TMP is nan! "); }}
2.4. Determine if null or undefined
The right approach:
var tmp = NULL; Null,nan,undefinedfunction Btnclick () {if (TMP = = null) {alert ("TMP is null or undefined!"); }}
Or
var tmp = undefined; Null,nan,undefinedfunction Btnclick () {if (tmp = = undefined) {alert ("TMP is null or undefined!"); }}
2.5. Judge whether it is undefined or Nan
Correct practice:
var tmp = NaN; Null,nan,undefinedfunction Btnclick () {if (IsNaN (TMP)) {alert ("TMP is NaN or undefined!"); }}
2.6. Determine if null or undefined or Nan
The right approach:
var tmp = NULL; Null,nan,undefinedfunction Btnclick () {if (!tmp) {alert ("TMP is null or undefined or nan!"); }}
null, undefined, NaN in JavaScript