Javascript typeof usage _javascript tips

Source: Internet
Author: User
if (document.mylist.length!= "undefined") {} This usage is incorrect.
The correct is if (typeof (Document.mylist.length)!= "undefined") {}
Or if (!isnan (Document.mylist.length)) {}
The typeof operand is undefined, and the return is "undefined".
The number of operands is typeof (x) = "Number"
String typeof (X) = "string"
Boolean value typeof (X) = "Boolean"
objects, arrays, and Null typeof (X) = "Object"
function typeof (X) = "function"
The typeof operator returns a String that represents the data type of an expression.
Possible strings are: "Number", "string", "Boolean", "Object", "function", and "undefined".
Such as:
Alert (typeof (123));//typeof (123) returns "Number"
Alert (typeof ("123"));//typeof ("123") returns "string"
typeof operator
Returns a string that is used to represent the data type of an expression.
typeof[() expression[]];
The expression parameter is any expression that needs to find the type information.
Cloud-dwelling community www.jb51.net more JavaScript data to access
Description
The typeof operator returns the type information as a string. There are six possible typeof return values: "Number," "String," "Boolean," "Object," "function," and "undefined."
Parentheses in the typeof syntax are optional.
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.