A javascript number type question
Why 1.toFixed(2) get 开发者_如何转开发syntax error while
var a = 1;
a.toFixed(2)
won't.
Moreover, why does 1.1.toFixed(2) run alright?
1.
starts a float so 1.toFixed()
is incorrect syntax. You could use (1).toFixed()
though.
1.1.toFixed()
works fine because after 1.1
you are already in a float so the parser won't take .
as the beginning of a float but as an object method call.
精彩评论