Most programming languages Support variables other than Boolean types as logical values for logical judgment such as if and while. although the rules are slightly different, the basic principles are basically the same. For example, in Javascript, the IF statement only denies the following values: false, 0, null, undefined, empty string. but if they are converted to boolean variables, the rules are as follows:
// Test the type conversion values of the five values var A = [false, 0, "", undefined, null]; for (VAR I = 0; I <5; I ++) {for (var j = 0; j <5; j ++) {alert (A [I] + "=" + A [J] + ": "+ (A [I] = A [J]) ;}}
Summary: false, 0, and "" (empty string) are always equal, no matter which one is in the front and which one is in the back. while undefined and null are always equal. however, the previous group and the last group are always different. from the language point of view, undefined and null do have almost no difference. There is no need to introduce these two constants. From the meaning point of view, undefined indicates that this variable does not exist, null indicates that the variable points to a null constant object. however, JavaScript does not need to worry about whether a variable exists. In the operation, it is not necessary to distinguish whether a variable is undefined or set to null,
This distinction adds a lot of trouble, because you need to consider one more case.