Space .toFixed 方法前的字符

Space character before .toFixed method

我注意到,如果您在 .toFixed 方法之前放置一个 space 字符,它将正常运行而不会出错。我明白为什么它与括号 (2).toFixed(2) 一起使用,但为什么它与 space 一起使用?

console.log(2 .toFixed(2))
// 2.00
console.log(2.toFixed(2))
// Uncaught SyntaxError: Invalid or unexpected token

请留下任何相关信息的链接。谢谢。

它只是(点)运算符之前的普通空格。

也许你也看看这里:dot notation

console.log(2 .toFixed(2))