-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] 第35天 请你解释一个为什么10.toFixed(10)会报错? #130
Comments
哦~~,原来是这样啊 所以我们可以这样修改下:
当然出现这个报错是因为前面这个数是整数,如果本来就是小数就不会出现这个报错。 |
10.toFixed(10) // Uncaught SyntaxError: Invalid or unexpected token
(10).toFixed(10) // "10.0000000000" 原因是js解释器对 |
. 当成float了 |
在我们的直觉上, 但实际上会出错,是因为 JS 的解释器对 解决的办法有下面几种:
参考文章: |
歧义之前没有注意到,会使用 |
原因是 toFixed前面跟一个整数时,他会把10.toFixed()这个“.”误解为小数点 |
|
哦~~,原来是这样啊 所以我们可以这样修改下: (10).toFixed(10) 当然出现这个报错是因为前面这个数是整数,如果本来就是小数就不会出现这个报错。 |
原因是 toFixed前面跟一个整数时,他会把10.toFixed()这个“.”误解为小数点 |
2 similar comments
原因是 toFixed前面跟一个整数时,他会把10.toFixed()这个“.”误解为小数点 |
原因是 toFixed前面跟一个整数时,他会把10.toFixed()这个“.”误解为小数点 |
第35天 请你解释一个为什么10.toFixed(10)会报错?
The text was updated successfully, but these errors were encountered: