JavaScript Language Basics 6

Source: Internet
Author: User

In the previous chapter we know that in JavaScript code, when you add a character to a numeric value, the value is converted to a character, which means that the value entered by the user is converted to a character.

Now we're going to do such an example, and I want to add 1 and 2:



Obviously the result is not what we want, now we change the code to look like this:



The result is what we want, 1+2=3.

This means that we can convert the character type to a numeric type parseint ().

If there are numeric values and strings in the input value, can we get the values we want?

Look at the following code:



It is possible to obtain a value, but the result is 2 is not 2.34, this is because the parseint () function It resolves to is not a valid value will stop parsing when parsing to. (dot) stopped parsing, then how can we get to 2.34, see the following code:



By code we know that using the parsefloat () function resolves to a floating-point number, which is the value we want to get,


Next look at a special case, if the input string does not have a valid value, then the use of these two functions will get what, see the following code:



The Nan value is a special value in JavaScript, indicating that it is not a value.



Reprint Please specify source:http://blog.csdn.net/hai_qing_xu_kong/article/details/40892573 Emotional Control _







JavaScript Language Basics 6

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.