Why is 10 .. toString () normal in JavaScript, and 10. toString () error? This problem has always plagued me. I took the time to collect and sort it out and share it with anyone who is interested in it, I hope to help you with this issue on stackoverflow, the famous Q & A website.
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::
The Code is as follows:
Console. log (10 .. toString (); // 10
Console. 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 sign, so the above Code is equivalent to the following:
The Code is as follows:
Console. log (10.). toString (); // normal
Console. log (10.) toString (); // in this case, of course, an error is returned (end) ^_^