This question is displayed 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::
Copy codeThe 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:
Copy codeThe Code is as follows:
Console. log (10.). toString (); // normal
Console. log (10.) toString (); // in this case, of course, an error is returned (end) ^_^