JavaScript raw data type

Source: Internet
Author: User

JavaScript data types are divided into primitive types (primitive type) and reference types (complex type).

First, the original type

JavaScript has 5 primitive types (primitive type), that is, Undefined, Null, Boolean, number, and String.

1.Number type

This type can represent both a 32-bit integer and a 64-bit floating-point number.

A special number value:

The first two are Number.MAX_VALUE and Number.min_value, which define the outer bounds of the set of number values. All ECMAScript numbers must be between these two values. However, the resulting numeric result can be calculated without falling between the two values.

When the number of calculations generated is greater than Number.MAX_VALUE, it is given a value of number.positive_infinity, which means no longer a numeric value. Similarly, calculations that generate less than Number.min_value will also be assigned a value of number.negative_infinity, meaning there is no longer a numerical value. If the calculation returns an infinity value, the resulting result can no longer be used for other calculations.

In fact, there are specific values that represent infinity, (as you guessed) that is Infinity. The value of Number.POSITIVE_INFINITY is INFINITY. The value of Number.negative_infinity is-infinity.

Because the infinity number can be positive or negative, a method can be used to determine whether a number is poor (rather than testing each infinite number separately). You can call the Isfinite () method on any number to ensure that the number is not infinite.

The last special value is NaN, which represents a non-number (not a digit). NaN is a strange special value. In general, this occurs when a type (String, Boolean, etc.) conversion fails. For example, to convert a word blue to a numeric value will fail because there is no value equal to it. As with infinity, NaN cannot be used for computational calculations. Another peculiar point of NaN is that It is not equal to itself, which means that the following code will return false:

Alert (nan = = nan);  Output "false"
2. String type
What is unique about the String type is that it is the only original type that has no fixed size. You can store 0 or more Unicode characters in a string, represented by a 16-bit integer.
Each character in the string has a specific position, starting at position 0, the second character at position 1, and so on. This means that the position of the last character in the string must be the length of the string minus 1:
String literals are declared by double quotation marks (") or single quotation marks ('). Java uses double quotation marks to declare a string, and to declare a character in single quotation marks. However, since ECMAScript has no character type, either of these representations can be used.
3. Boolean type

It has two values of true and false.

If JS expects a location to be a Boolean value, the existing value at that location is automatically converted to a Boolean value. The conversion rule is that except for the following six values are converted to false, the other values are treated as true.

undefinednullfalse0NAN""(空字符串)

4. Undefined type

As mentioned earlier, the Undefined type has only one value, which is Undefined. When the declared variable is not initialized, the default value of the variable is undefined.

5. Null Type

Another type with only one value is null, and it has only one private value, NULL, which is its literal. The value undefined is actually derived from the value null, so ECMAScript defines them as equal.

Although the two values are equal, they have different meanings. Undefined is a value that is assigned to a variable when it is declared but not initialized, and null is used to represent an object that does not already exist (this is briefly described when discussing the typeof operator). If the function or method is to return an object, the object returned is usually null when it is not found.








JavaScript raw data type

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.