0

I was just playing around javascript toString method, then when i tried the number.toString() it gave me error, but when i tried number..toString() it gave me the result that i was expecting for the first code.

1. Can any one explain what is the reason for this / What is the difference here ?
2. why is 49.toString() is giving me error ? does that mean number has no toString() method ?  
3. What is happening here exactly ?

JS Code

49.toString(); //SyntaxError: Unexpected token ILLEGAL

49..toString(); //"49"
Razer
  • 39
  • 1
  • 6

1 Answers1

0

The period is being parsed as a decimal point. That's why you're getting a syntax error. In the double period case you are calling toString on a floating point number not the integer 49.

b4hand
  • 9,550
  • 4
  • 44
  • 49