JavaScript in use why 10. ToString () Normal and 10.toString () error _javascript Tips

Source: Internet
Author: User
This question was seen on the--stackoverflow of the famous question and answer website.
I have seen this problem of JavaScript before, but I didn't know it well, today I saw the answer on the StackOverflow, I feel good, and write it down to share with you.

The description of the problem is this :
Copy Code code as follows:

Console.log (10..toString ());//10
Console.log (10.toString ());//syntaxerror:unexpected token illegal

Why the former is normal, and the latter error.

The reason is, in JavaScript, the "." Behind the number. The meaning of the operator is not certain. Because it may be either a flag for floating-point numbers or an operator of an object's properties. But the JavaScript interpreter treats him as a floating-point symbol, so the above code is equivalent to the following
Copy Code code as follows:

Console.log (10.). ToString ());/Normal
Console.log (10.) ToString ());//In this case, of course, there is an error (end) ^_^
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.