Use the typeof Method to Determine the undefined type, typeofundefined

Source: Internet
Author: User

Use the typeof Method to Determine the undefined type, typeofundefined

For JavaScript to determine the undefined type, the typeof method is used. typeof returns a string, where one is undefined.

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 ".
Be sure to pay attention when using it.


JavaScript typeof ()

Arrays are often used in js. For example, if multiple inputs with the same name are generated dynamically, You need to determine whether the input is an array during submission.

If (document. mylist. length! = "Undefined") {} This usage is incorrect.

Correct is if (typeof (document. mylist. length )! = "Undefined "){}

Or if (! IsNaN (document. mylist. length )){}

The number of typeof operations is undefined, and "undefined" is returned ".

Number of operations: number typeof (x) = "number"

String typeof (x) = "string"

Boolean value typeof (x) = "boolean"

Object, array, and null typeof (x) = "object"

Function typeof (x) = "function"

The typeof operator returns a string that represents the Data Type of the expression.
Possible strings include: "number", "string", "boolean", "object", "function", and "undefined ".
For example:
Alert (typeof (123); // typeof (123) returns "number"
Alert (typeof ("123"); // typeof ("123") returns "string"

In java, how does one determine whether the variable is of the int type? If typeof is used, an error is returned?

Java does not contain typerof. You must use instanceof
The basic type does not work. You must use an object.
Integer I = 0;
If (I instanceof Integer ){
System. out. println ("haha ");
}

String str = "abc ";
If (str instanceof Object ){
System. out. println ("haha ");
}
Hope to help you.

Related Article

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.