TypeOf Usage Summary _javascript techniques in JavaScript

Source: Internet
Author: User
Tags numeric value

In JS used in the array, such as multiple names of the same () input, if the dynamic generation (of), the submission of the 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)) {}

typeof () is not defined, the return (of) 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"

The 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 the 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."
The parentheses in the TypeOf syntax are optional. Introduction to the TypeOf operator:
TypeOf is a unary operation, which can be any type of operation before it is placed in one op-count.
The return value is a string that describes the type of the operand.

Do you know the result of the following typeof operation?

typeof (1);
typeof (NaN);
typeof (Number.min_value);
typeof (Infinity);
typeof ("123");
typeof (True);
typeof (Window);
typeof (document);
typeof (NULL);
typeof (Eval);
typeof (Date);
typeof (SSS);
typeof (undefined);

How many do you have?

If you look at it later, not very clear, please see below (understand the people do not have to look down):
typeof is a unary operator, which returns a result that is always a string, and for different operands, it returns a different result.

The specific rules are as follows:

For the operand of a numeric type, the value returned by TypeOf is number. For example: typeof (1), the return value is number.

The above is a regular number, and for unconventional numeric types, the result returns a number. such as typeof (Nan), Nan in
JavaScript represents a special Non-numeric value, although it is itself a numeric type.

In JavaScript, there are several special types of numbers:

Infinity represents Infinity Special value
NaN Special non-numeric value
Number.MAX_VALUE The maximum number that can be represented
Number.min_value can represent the smallest number (closest to 0)
Number.NaN Special non-numeric values
Number.POSITIVE_INFINITY a special value representing positive infinity
Number.negative_infinity represents a special value of negative infinity

The above special type, which is typeof, will result in number.

For a string type, the value returned by TypeOf is String. For example, the value returned by typeof ("123") is a string.
For a Boolean type, the value returned by TypeOf is a Boolean. For example, the value returned by typeof (True) is a Boolean.
The values returned for objects, arrays, and Null are object. For example, typeof (window), typeof (document), typeof (NULL) return values are object.
For a function type, the value returned is a function. For example: typeof (eval), the value returned by typeof (Date) is a function.
If the OP count is undefined (for example, a nonexistent variable, function, or undefined), it will return undefined. For example: typeof (SSS), typeof (undefined) are returned to undefined.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.