Data types for JavaScript

Source: Internet
Author: User
As written in the JavaScript Advanced programming:

JS data types are divided into basic types and reference types.

So what is the basic data type?

For example, String,number,boolean are basic data types. In layman's words, they can save a value, but they cannot invoke a method on a saved value.

However, you can create a new instance of the base type by using the following code:

For example:

var numberobject = new number (10); The actual arguments for the new instance in parentheses

The book has introduced, the type of detection object can be divided into TypeOf and Instanceof method, then what difference do they have?

Conceptually, typeof is suitable for detecting basic data types. The instanceof is suitable for detecting reference types.

Here is an example:

var numberobject = new number (10);

var numbervalue = 10;

Alert (typeof Numberobject); Returns "Object"

Alert (typeof Numbervalue); Returns "Number"

Alert (numberobject instanceof number); Returns True

Alert (numbervalue instanceof number); Returns false

The above example shows that the data type value can be returned correctly when TypeOf is used to detect the base data type. However, if a reference type is detected, only object is returned.

However, when you use instanceof to detect a reference type value, you can return the correct boolean value.

Data types for JavaScript

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.