更新时间:2022-02-28 08:32:00
表达式 0.0
和 00.0
的解析方式不同。
The expressions 0.0
and 00.0
are parsed differently.
0.0
被解析为数字文字 1
00.0
被解析为: 00
- 八进制数字文字 2
。
- 属性访问者 0
- 标识符名称0.0
is parsed as a numeric literal 1
00.0
is parsed as:
00
– octal numeric literal 2
.
– property accessor0
– identifier name您的代码会引发语法错误,因为 0
不是有效的JavaScript标识符。以下示例有效,因为 toString
是有效的标识符:
Your code throws syntax error because 0
is not a valid JavaScript identifier. The following example works since toString
is a valid identifier:
00.toString
1 第7.8.3节 - 前导0后面可以跟小数点分隔符或 ExponentPart
2 B部分.1.1 - 前导0后面可以跟 OctalDigits
1 Section 7.8.3 – Leading 0 can be followed by decimal separator or ExponentPart
2 Section B.1.1 – Leading 0 can be followed by OctalDigits