JS determines the undefined type
Today, when showmodaldialog is used to open the page and return values. When you click the close button on the page or click Close in the browser, the returned value is undefined.
Therefore, smart judgment
VaR revalue = Window. showmodaldialog ("","","");
If (revalue = undefined ){
Alert ("undefined ");
}
Unable to judge, found the information to use typeof
Method:
If (typeof (revalue) = "undefined "){
Alert ("undefined ");
}
Typeof returns a string, which may be "Number", "string", "Boolean", "object", "function", or "undefined"
Differences between undefined, null, and Nan in JS
1. Type Analysis:
The data types in JS include undefined, Boolean, number, string, and object. The first four are original data types and the second are reference data types.
VaR A1;
VaR a2 = true;
VaR a3 = 1;
VaR A4 = "hello ";
VaR A5 = new object ();
VaR A6 = NULL;
VaR A7 = Nan;
Var a8 = undefined;
Alert (typeof a); // display "undefined"
Alert (typeof a1); // display "undefined"
Alert (typeof a2); // displays "boolean"
Alert (typeof a3); // display "number"
Alert (typeof a4); // display "string"
Alert (typeof a5); // displays "object"
Alert (typeof a6); // displays "object"
Alert (typeof a7); // display "number"
Alert (typeof a8); // display "undefined"
From the code above, we can see that undefined is undefined for undefined values and definitions. null is a special object and NaN is a special number.
2. Comparison
Var a1; // The a1 value is undefined.
Var a2 = null;
Var a3 = NaN;
Alert (a1 = a2); // display "true"
Alert (a1! = A2); // display "false"
Alert (a1 = a3); // display "false"
Alert (a1! = A3); // display "true"
Alert (a2 = a3); // display "false"
Alert (a2! = A3); // display "true"
Alert (a3 = a3); // display "false"
Alert (a3! = A3); // display "true"
From the code above, we can draw a conclusion: (1) undefined is equal to null; (2) NaN is not equal to any value and is not equal to itself.
Var a = undefined; equivalent to var;
Var B = false;
Var c = null;
Alert (a = B); // false
Alert (a = c); // true
Alert (B = c); // false
JavaScript undefined attributes
Definition and usage
The undefined attribute is used to store the undefined value of JavaScript.
Syntax
Undefined
Description
You cannot use the for/in loop to enumerate the undefined attribute, or use the delete operator to delete it.
Undefined is not a constant. You can set it to another value.
Undefined is returned when you try to read non-existent object attributes.
Tips and comments
Tip: You can only use the = operation to test whether a value is undefined, because the = operator considers the undefined value to be equivalent to null.
Note: null indicates no value, while undefined indicates an undeclared variable, a declared variable without a value, or an object attribute that does not exist.
Instance
In this example, we will check the undefined one of the two variables:
<Script type = "text/javascript">
Var t1 = ""
Var t2
If (t1 = undefined) {document. write ("t1 is undefined ")}
If (t2 = undefined) {document. write ("t2 is undefined ")}
</Script>
Output:
T2 is undefined