JavaScript data type (i)--typeof operator, Boolean, NULL, and undefined

Source: Internet
Author: User

One, JavaScript data type

The data types of JavaScript fall into the following categories:

Five simple data types: Undefined,null,boolean,string,number.

A complex data type: Object.

Second, typeof operator

Here are a few short stories to summarize it, before summing up, first know a very useful operator--typeof.

The typeof operator is an operator used to detect JavaScript data types, which returns one of the above data types. But there is a special case where the null data type returns object, that is, typeof null to return an object. This is because NULL is understood to be an empty object reference. This involves two large data types, null and undefined. We recognize and differentiate them below.

Third, Boolean

The Boolean value has only two literals: true and false. This type uses quite a lot, note that these two literals are not equal to the values 1 and 0, and that true and false are case-sensitive, that is, true is not a Boolean value, but a simple identifier.

When you want to convert a value to a Boolean value, you can call the Transform function Boolean (), and for any type of data using a transform function, you can convert them to a Boolean value, and all types of data are converted with the corresponding conversion rules. Not listed here, to cite a few examples:

Boolean (""); False

Boolean (O and Nan); False

Boolean (NULL); False

Boolean ("Hello world!"); /true;

Iv. null and undefined

Both null and undefined are data types that have only one value, and undefined represents the value of an uninitialized variable, which is

var//true;

And null represents an empty object pointer, so this is why typeof null returns object.

In fact, undefined is derived from Null,so, alert (null = = undefined) , and returns True.

This article ends with two other types of data.

JavaScript data type (i)--typeof operator, Boolean, NULL, and undefined

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.