Why does 3toString () throw a syntax exception and does 3..toString () work fine?

why in javascript 3.toString () throws an exception and 3..toString () works fine? I saw this in a funny presentation about javascript, but I can't find the information WHY. Thank you in advance.

+4
source share
1 answer

Since the decimal point is the real part of the number, so the first point is considered to be numeric, the second for the chain.

If you prefer to avoid a double period, you can:

(3).toString();

Or:

'' + 3;

Or:

String(3);
+9
source

Source: https://habr.com/ru/post/1529965/


All Articles