JavaScript in parseint (), 08, 09, return 0

Source: Internet
Author: User

The return value is 0 when using parseint (08), parseint (09) For integer conversions in JavaScript.

Tools/Materials
  • Browser
  • Text Editor
Method/Step
  1. In JavaScript, when converting integers using parseint (08), parseint (09), the return value is 0, and parseint ("07") is correct, because when there is "0" in front, JavaScript would think of this as an octal number, and "08" and "09" were not a valid octal number, so that caused the problem.

    The parseint function actually has another parameter that shows that the parseint is handled in decimal.

    The workaround:

    parseint ("08", 10) or parseint ("09", 10)

    Number ("08") or number ("09")

    This should not be called a bug, but it is our technology is not refined, it does not understand, will appear this headache problem.

JavaScript in parseint (), 08, 09, return 0

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.