Home > Web Front-end > JS Tutorial > body text

Why is 10..toString() normal but 10.toString() error when using javascript_javascript skills

WBOY
Release: 2016-05-16 17:44:00
Original
992 people have browsed it

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:

Copy the code The code is as follows:

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
Copy code The code is as follows:

console.log((10.).toString());//Normal
console.log((10.)toString());//In this case , of course an error was reported (End) ^_^
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template