Why don’t number literals have access to Number methods? [duplicate]

You can access it the same way, it’s a different parsing issue here, to do it, use a slightly different syntax:

(1).toString()

Numbers can have decimals, so the syntax for ending in a decimal is a bit ambiguous when you go to parse the code, use parenthesis to be valid. It’s a bit clearer when you see that this is also valid:

(1.).toString()

However with just 1.toString() it’s trying to parse as a number with a decimal, and it fails.

Leave a Comment