What's the difference between the following code?
var a = 1;
a.toString(); // outputs: "1"
But this throws an error:
1.toString();
SyntaxError: Unexpected token ILLEGAL
Why? Why does the first code work but the second code throws an error?
With method invocations, it is important to distinguish between the floating-point dot and the method invocation dot.
Thus, you cannot write 1.toString();
you must use one of the following alternatives:
1..toString()
1 .toString() //space before dot
(1).toString()
1.0.toString()
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