开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜