Usage of javascript typeof and introduction to the typeof operator [Details] Page 1/2

Source: Internet
Author: User

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"
Typeof Operator
Returns a string that represents the expression's data type.
Typeof [() expression [];
The expression parameter is an arbitrary expression that needs to be searched for type information.
Description
The typeof operator returns the type information as a string. There are six possible types of 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.