2.toString()
The interpreter sees 2
and thinks, "oh, a number!" Then, it sees the dot and thinks, "oh, a decimal number!" And then, it goes to the next character and sees a t
, and it gets confused. "2.t
is not a valid decimal number," it says, as it throws a syntax error.
2..toString()
The interpreter sees 2
and thinks, "oh, a number!" Then, it sees the dot and thinks, "oh, a decimal number!" Then, it sees another dot and thinks, "oh, I guess that was the end of our number. Now, we're looking at the properties of this object (the number 2.0)." Then, it calls the toString
method of the 2.0
object.