为什么我不能用一个点访问整数的属性? [英] Why can't I access a property of an integer with a single dot?

查看:18
本文介绍了为什么我不能用一个点访问整数的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我试着写

3.toFixed(5)

存在语法错误.使用双点、放置一个空格、将三个放在括号中或使用括号表示法可以使其正常工作.

there is a syntax error. Using double dots, putting in a space, putting the three in parentheses or using bracket notation allows it to work properly.

3..toFixed(5)
3 .toFixed(5)
(3).toFixed(5)
3["toFixed"](5)

为什么单点符号不起作用,我应该使用这些替代方法中的哪一种?

Why doesn't the single dot notation work and which one of these alternatives should I use instead?

推荐答案

句点是数字的一部分,所以代码会解释为:

The period is part of the number, so the code will be interpreted the same as:

(3.)toFixed(5)

这自然会产生语法错误,因为您不能立即在数字后面加上标识符.

This will naturally give a syntax error, as you can't immediately follow the number with an identifier.

任何防止将句点解释为数字一部分的方法都可以.我认为最清楚的方法是在数字周围加上括号:

Any method that keeps the period from being interpreted as part of the number would work. I think that the clearest way is to put parentheses around the number:

(3).toFixed(5)

这篇关于为什么我不能用一个点访问整数的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆