Js judges the undefined type and js judges the undefined type.

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.