1

I noticed that if you put a space character before .toFixed method, it will work without errors. I understand why it's work with a parenthesis (2).toFixed(2), but why does it work with space?

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

Please leave links to any information about this. Thanks.

1 Answers1

2

It is just the usual whitespace before the (dot) operator.

Maybe you have a look here, too: dot notation

console.log(2 .toFixed(2))
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392