Javascript函数toString

Joy*_*Lee 6 javascript numbers

请参阅以下代码:

2.toString();   // error
2..toString();  // "2"
2...toString(); // error
Run Code Online (Sandbox Code Playgroud)

我想知道为什么2..toString()可以运行没有错误以及运行时会发生什么?

有人可以解释一下吗?

Nik*_*nov 8

http://shamansir.github.io/JavaScript-Garden/en/#object

一个常见的误解是数字文字不能用作对象.这是因为JavaScript解析器中的一个缺陷试图将数字上的点符号解析为浮点文字.

2.toString(); // raises SyntaxError
Run Code Online (Sandbox Code Playgroud)

有几种解决方法可用于使数字文字也充当对象.

2..toString(); // the second point is correctly recognized
2 .toString(); // note the space left to the dot
(2).toString(); // 2 is evaluated first
Run Code Online (Sandbox Code Playgroud)