100['toString'] //does not fail
100.toString //fails
why?
100.toString is not same as 100.toString() . So why in the second case I am not getting the function as returned value?
The second line fails because it is parsed as a number "100.", followed by "toString".
To use the dot notation, Any of the following will work:
(100).toString
100.0.toString
100..toString
var a = 100;
a.toString
If you are trying to call the toString
function , you will also need to include the parentheses:
(100).toString()
100.0.toString()
100..toString()
var a = 100;
a.toString()
I prefer using parentheses (or a variable, if I already have one obviously), because the alternatives could be confusing and unintuitive.
Use (100).toString
instead.
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