The usage of typeof in JS

Source: Internet
Author: User

One

Often in the JS to use the array, such as multiple names of the same input, if dynamically generated, the submission will need to determine whether it is an array.

if (document.mylist.length! = "undefined") {} This usage is incorrect.

Correct is if (typeof (Document.mylist.length)! = "undefined") {}

Or if (!isnan (Document.mylist.length)) {}

The operand of typeof 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 is used to represent the data type of the 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"

Two
typeof operator

Returns a string that is used to represent the data type of the expression.


typeof[() expression[];

The expression parameter is any expression that needs to find type information.


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.

The usage of typeof in JS

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.