Why does calling 152..toString(2)
return a binary string value of "10011000"
, when a call to 152.toString(2)
throws the following exception?
"SyntaxError: identifier starts immediately after numeric literal"
It seems to me that it's intuitive to want to use the latter call to toString()
, as it looks & feels correct. The first example just seems plain odd to me.
Does anyone know why JavaScript was designed to behave like this?
(10).toString()
toString
in10.toString
is the start of a fraction, while in the later case you have 0 as fraction and then run toString on the float. This would probably mean thatvar n = 10.;
would be valid as well (never tried though).10.0.toString()
is also works