开发者

A javascript number type question

开发者 https://www.devze.com 2023-02-06 15:37 出处:网络
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

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

精彩评论

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