In JavaScript, why is 10 .. tostring () normal, and 10. tostring () error?

Source: Internet
Author: User

This is a question on the famous Q & A website --Stackoverflow.

I have also seen this question about JavaScript before, but I have no in-depth understanding. Today I have seen the answer on stackoverflow. It feels good. I will write it down and share it with you.

The problem is described as follows:

 
1Console. Log (10.. Tostring ());//102 3Console. Log (10. Tostring ());//Syntaxerror: Unexpected token illegal

Why is the former normal while the latter reporting an error.

The reason is that in Javascript, the "." Operator after the number is meaningless. It can be both a floating point sign and an operator that obtains the attributes of an object. However, the javascript interpreter regards it as a floating point number, so the aboveCodeIt is equivalent to the following:

1Console. Log (10.). tostring ());//Normal2 3Console. Log (10.) tostring ());//In this case, of course, an error is reported.

(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.