0

y = 15;
let x = y.toString(10);
console.log(x)

This prints '15' but

let x = 15.toString(10);
console.log(x)

gives Error: Invalid or unexpected token Why?

sjahan
  • 5,720
  • 3
  • 19
  • 42
  • 1
    The snippet tool's syntax highlighting gets confused for the same reason. – RemcoGerlich Jul 19 '18 at 09:13
  • @James Thorpe I looked for this thoroughly on stack overflow before asking and nothing remotely similar was even among the 10 suggestions when I was typing the title. If this already has an answer, kindly provide the link to the same and I shall willingly delete my question. – Upasana Sengupta Jul 19 '18 at 09:30
  • @UpasanaSengupta The link to the other Q&A is at the top of the post in the yellow box - being marked as a duplicate isn't a bad thing - hopefully you still get your answer, and if your question is phrased slightly differently to the other, it will act as a sign post for future searches to hopefully find the answer also. – James Thorpe Jul 19 '18 at 09:32

1 Answers1

5

It works with another dot for separating the property from number.

let x = 15..toString(10);
console.log(x);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392