Js judges the undefined type and js judges the undefined type.
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
How to judge undefined and null in JS
Note: This method can be used to determine both undefined and null. Var exp = undefined; if (typeof (exp) = undefined) {alert ("undefined");} typeof returns a string, which has six possibilities: "number", "string", "boolean", "object", "function", and "undefined" are correct usage: var exp = undefined; if (typeof (exp) = "undefined") {alert ("undefined"); if (exp = null) {alert ("is null");} When exp is undefined, it will also get the same result as null, although null and undefined are different. Note: This method can be used to determine both null and undefined. Var exp = null; if (! Exp) {alert ("is null");} If exp is undefined or the number is zero, the same result will be obtained as null, although null is different from the two. Note: You can use this method to determine whether null, undefined, and numeric values are zero at the same time. Var exp = null; if (typeof (exp) = "null") {alert ("is null");} for backward compatibility, when exp is null, typeof always returns objects. Var exp = null; if (isNull (exp) {alert ("is null");} No isNull function in JavaScript. The following is the correct usage: var exp = null;