Copy Code code as follows:
if (revalue== undefined) {
Alert ("undefined");
}
Found that the judge does not come out, finally checked the data to use the TypeOf method:
if (typeof (revalue) = = "undefined") {
Alert ("undefined");
}
typeof returns a string of six possible: "Number", "string", "Boolean", "Object", "function", "undefined"
3.4 Data types
There are 5 simple data types (also known as basic data types) in ECMAScript: Undefined, Null, Boolean, number, and string. There are also 1 kinds of complex data types--object,object are essentially composed of a set of unordered name-value pairs. ECMAScript does not support any mechanism for creating custom types, and all values will eventually be one of the 6 data types mentioned above. At first glance, it seems that only 6 data types are not sufficient to represent all the data, but since the ECMAScript data type is dynamic, it is not necessary to redefine other data types.
3.4.1 typeof operator
Since ECMAScript is loosely typed, there is a need to have a means to detect the data type of a given variable--typeof is the operator responsible for providing this information. Using the typeof operator on a value may return one of the following strings: "undefined"-if the value is undefined, "boolean"-if the value is a Boolean, "string"-if the value is a string;
24 3rd Chapter Basic Concepts
"Number"-if the value is numeric, "Object"-if the value is an object or null; "function"-if the value is a function. Here are a few examples of using the TypeOf operator:
var message = "some string"; Alert (typeof message); ' String ' Alert (typeof (Message)); "String" alert (typeof 95); "Number"
Typeofexample01.htm
These examples show that the operands of the typeof operator can be either a variable (message) or a numeric literal. Note that TypeOf is an operator rather than a function, so parentheses in the example are available, but are not required. Sometimes, the typeof operator returns some confusing but technically correct value. For example, calling typeof null returns "Object" because the special value NULL is considered to be an empty object reference. Safari 5 and previous versions, Chrome 7, and previous versions return "function" when you call the TypeOf operator on a regular expression, and other browsers return "object" in this case.
From a technical standpoint, a function is an object in ECMAScript, not a data type. However, functions do have some special properties, so it is necessary to differentiate functions and other objects by typeof operators.
Copy Code code as follows:
function Test1 () {
VAR message;
if (typeof (message) = = "undefined")
Alert ("Variable value not defined");
Else
alert (message);
}
var cc=test1;
CC ();