使用或不使用变量的数字之间的差异 [英] difference between numbers using or without using variable
本文介绍了使用或不使用变量的数字之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码有什么区别?
var a = 1;
a.toString(); // outputs: "1"
但这会引发错误:
1.toString();
SyntaxError:意外的令牌非法
SyntaxError: Unexpected token ILLEGAL
为什么?为什么第一个代码可以正常工作,但是第二个代码却抛出错误?
Why? Why does the first code work but the second code throws an error?
推荐答案
使用方法调用,区分浮点点和方法调用点很重要>.因此,您无法编写 1.toString();
,您必须使用以下替代方法之一:
With method invocations, it is important to distinguish between the floating-point dot and the method invocation dot.
Thus, you cannot write 1.toString();
you must use one of the following alternatives:
1..toString()
1 .toString() //space before dot
(1).toString()
1.0.toString()
这篇关于使用或不使用变量的数字之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文