Js uses the typeof Method to Determine the undefined type, typeofundefined
Js determines the undefined type
if (reValue== undefined){alert("undefined");}
The system found that the data could not be determined, and finally found the information to use the typeof method:
if (typeof(reValue) == "undefined") { alert("undefined"); }
Typeof returns a string, which may be "number", "string", "boolean", "object", "function", or "undefined"
Js determines whether the variable is undefined
Many friends may think that undefined is an error that will be prompted only when no variable is defined in js. In fact, undefined is a special variable in js. We can also define it in advance, next I will introduce js undefined usage.
JavaScript has two special data types: undefined and null. Let's talk about the undefined judgment.
Js judges the undefined type code as follows: copy the Code if (reValue = undefined ){
Alert (undefined);} was unable to judge, and finally found the information to use the typeof method: the code is as follows:
If (typeof (reValue) = undefined ){
Alert (undefined);} typeof returns a string, which can be number, string, boolean, object, function, or undefined.
The following is an incorrect usage: the code is as follows: copy the code var exp = undefined;
If (exp = undefined ){
Alert (undefined);} If exp is null, the same result will be obtained as undefined, although null and undefined are different. Note: This method can be used to determine both undefined and null.
The following code copies the code var exp = undefined;
If (typeof (exp) = undefined ){
Alert (undefined);} when judging whether it is undefined, you must add quotation marks on both sides. Otherwise, the test fails (Personal Test Result !) The var bank_value variable of the instance. When alert is used, some of its values are undefined. Therefore, I use the following judgment to determine whether it is equal to undefined.
Copy the code var yinvalue as follows;
If (yinvalue = 'undefined') {break;} is found to be incorrect and there is no entry condition. Later, I checked it online. The Code is as follows: copy the Code if (typeof (yinvalue) = 'undefined') {break;} typeof to return a string. There are six possibilities: number, string, boolean, object, function, undefined
In JavaScript, typeof ()! = 'Undefined,
Typeof (var) is used to determine whether a variable is an array.
Javascript often requires operations on HTML controls. As you know, if the names of HTML spaces are the same,
You can use document. getElementsByName to obtain an array.
If you want to use if (document. aaa. length! = "Undefined ").
If there are multiple controls (that is, arrays) on the page, an error is returned.
Use if (typeof (document. aaa. length )! = 'Undefined ').
========================================================== ======================================
As for if (var = 'undefined'), it is necessary to determine whether the variable is undefined, that is, whether it does not exist,
In the simplest example, your js contains two functions: function a (a1, a2 ),
It has two parameters, a1 and a2, and function B (),
Call a: a (var) in B );
Only one parameter is passed to function a, and the a2 value in function a is undefined.
========================================================== ======================================
Var in if (var) is a boolean variable, which has only the values true and false. if var = true,
The code in if {} will be executed. Otherwise, the code will be skipped.