JS4 data types, type conversions

Source: Internet
Author: User

ECMAScript: Standard, Core
HTML Tag type: block, inline, inline-block, table ...
The data type in JS: Number, String, Boolean, function, object (obj, [], {}, null), undefined
Ii. typeof Judging data types

    1. "Undefined" If this value is not defined
    2. "Boolean" If this value is a Boolean value
    3. "String" If this value is a string
    4. "Number" If this value
    5. "Object" If this value object or null
    6. ' function ' If this value function

such as Var a=123;

Alert (typeof a)//number

Third, numerical conversion

Explicit type conversions (coercion type conversions): A total of three functions
Conversion rules for number () functions

If it is a Boolean, True and False are converted to 1 and 0, respectively.

If it is a numeric value, simply pass in and return

If it is a null value, returns 0

If it is undefined, return Nan

L if it is a string, follow these rules

1) If the string contains only numbers (including those preceded with a sign), it is converted to a decimal value [first bit in front if with 0 direct ignore]

2) If the string contains a valid floating-point format, it is converted to the corresponding floating-point value [front first bit if with 0 direct ignore]

3) If the string contains a valid hexadecimal format, convert it to a decimal integer value of the same size

4) If the string is empty (does not contain any characters), convert it to 0

5) If the string contains characters other than the above format, convert it to Nan

parseint () function conversion rules take integers only

When a string is converted, the spaces preceding the string are automatically ignored until the first non-whitespace character is found

Note: 1) If the first character is not a numeric character or a minus sign, it will return Nan

2) If the first character is a numeric character or minus sign, the second character will continue to be parsed until it is resolved or a non-numeric character is encountered
Parsefloat () function conversion rules

Note: Only the first decimal point in a string is valid

Implicitly-Typed conversions:

+ 200+ ' 3 ' into a string

-*/% ' 200 '-3 becomes a number

++--into numbers.

Comparison of >< numbers, Comparison of strings

! Turn the data type on the right to a Boolean value

JS4 data types, type conversions

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.