JavaScript data types

Source: Internet
Author: User

The data types in 1.JavaScript include: string, number, Boolean, null, Undefined, Array, object.
The data types in 2.JavaScript can be divided into primitive types and reference types. Where string, number, Boolean, NULL,

Undefined belong to the original type, others are reference types.
3. The easiest thing to judge in a reference type is the method, because the TypeOf directly returns function, and the others are object. So
Reference types other than the judging method need to be judged by instanceof, the instanceof operator is constructed with an object and a
The function is a parameter, and if the object is an instance of the type specified by the constructor, Instanceof returns true;
False The instanceof operator can also be used to identify inherited types. All reference types in JavaScript are inherited from Object
Type, use instanceof to detect the following example:

var items = [];
var object = {};

function reflect (value) {
return value;
}

Console.log (items instanceof Object); True
Console.log (Object instanceof object); True
Console.log (reflect instanceof Object); True
4. Identification array: ECMAScript 5 introduces Array.isarray () to unambiguously identify whether a value is an instance of array, regardless
The value is from where the method returns true for an array from any context.
5. There are 3 types in the original package type (String, number, and Boolean), and the value of these special reference types is to make

Primitive type variables can be used as easily as reference type values (that is, objects), and their presence makes the original type variable callable

Methods to accomplish some common operations. The original type value holds the simple data value, cannot have its own property and method is undoubtedly

In fact, here, the original wrapper types in JavaScript are behind the scenes to help us do a series of work to make our

Ability to call library methods using the original type.
6.console.log (typeof null); "Object", so we cannot use the TypeOf operator to determine whether a variable is

Empty type. The best way to determine whether an empty type is a direct and null comparison, as in the following example:

Value is a variable to determine whether the type is empty
Console.log (value = = null); True or False


http://blog.csdn.net/qq_20974467/article/details/49357269

JavaScript data types

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.