2

What is difference between (1) and 1.

1.toString() //Will throw error
1.toFixed(1) //Will throw error
(1).toString() // output "1"
(1).toFixed(1) // output 1.0
Jagajit Prusty
  • 2,070
  • 2
  • 21
  • 39

1 Answers1

6

The trailing period on 1. is part of the number -- the compiler reads it as a decimal point, not as the dot operator. This makes an identifier immediately following the number unexpected.

Consider, for comparison: 1.0toString()