JS data type and type conversion

Source: Internet
Author: User

(1) display conversion type:

1.Number (a) is used to convert object a as a whole.

var a= ' 12345 ';

Number (a); a=12345

2.parseInt (a) is used to convert an object a from front to back, to start with a non-numeric stop conversion, to convert to an integer.

var a= ' 100px ';

parseint (a); a=100;

var a= ' +100px ';

parseint (a); a=100 for some of the ' +,-, Space ' symbols can be identified

3.parseFloat (a,10) is used to convert object a from post to decimal ; ' denotes decimal.

var a= ' 12.34 yuan ';

Parsefloat (a); a=12.34;

var a= ' 12.34.12 yuan ';

Parsefloat (a);     a=12.34; only one decimal points can be identified

(2) implicit conversion type:

1.+ (200+'1') converted to a string

2.-*/% ('3') converted to digital

3.++--(a= '; a++ ') converted into numbers

Comparison of 4.> < numbers is different from string comparison

Alert (' >9 '); True

Alert (' Ten ' > ' 9 '); False

5.! Inverse (converts the right data type to a Boolean value)

6. = = value comparison; = = = The comparison of the advanced types, then the comparison of the values

Alert (' 2 ' ==2); True

7.isNaN used to determine whether the number is the number returned false , not a numeric return true

(Working principle: First Use the number () method to convert, and then judge)

IsNaN (' 250 '); False

JS data type and type conversion

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.