why in javascript 3.toString() throws exception and 3..toString() works fine? I saw it in a funny presentation about javascript but I cannot find the info WHY. Thank you in advance.
Because a decimal point is a valid portion of a number, so the first dot is considered numeric, the second is for chaining.
If you'd prefer to avoid the double-period you could instead do:
(3).toString();
Or:
'' + 3;
Or:
String(3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With