I saw this question on the famous question and answer website - stackoverflow.
I have seen this question about JavaScript before, but I didn’t understand it in depth. Today I saw the answer on StackOverflow. I feel good about it. I wrote it down and shared it with everyone.
The description of the problem is like this:
console.log(10..toString());//10
console.log(10.toString());//SyntaxError: Unexpected token ILLEGAL
Why does the former work normally but the latter reports an error?
The reason is that in JavaScript, the meaning of the "." operator after the number is uncertain. Because it may be a symbol of a floating point number, or it may be an operator that takes the properties of an object. But the JavaScript interpreter treats it as a symbol of floating point numbers, so the above code is equivalent to the following
console.log((10.).toString());//Normal
console.log((10.)toString());//In this case , of course an error was reported (End) ^_^