Why does a method like `toString` require two dots after a number?
When you enter 42.toString()
it will be parsed as 42 with decimal value "toString()" which is of course illegal. 42..toString()
is simply a short version of 42.0.toString()
which is fine. To get the first one to work you can simply put paranthesis around it (42).toString()
.
With just 42.toString(); it's trying to parse as a number with a decimal, and it fails.
and when we write 42..toString(); taken as 42.0.toString();
we can get correct output by
(42).toString();
(42.).toString();
Can refer Link for .toString() usage
it is like 42.0.tostring() so it show's decimal point you can use (42).toString() 42 .toString() that also work there is space between 42 and dot. This is all because in javascript almost everything is object so that confusion in dot opt.