This article mainly introduced the JS judgment undefined type realization method, needs the friend to be possible to refer to under
Code is as follows: if (revalue== undefined) { alert ("undefined"); } found that the judge does not come out, finally checked the data to be used 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 ECMAScript have 5 Simple data types (also known as basic data types): 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 Given that 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 for a value may return one of the following strings: "undefined"-if this value is undefined; "Boolean"-if this value is a Boolean; "string"-if this value is a string; 24 3rd Chapter The basic concept "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 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 undefined"); nbsp else alert (message); } var cc=test1; cc ();