我总是通过向数字添加空字符串来将数字转换为字符串:
var string = 1 + '';
但是,JSLint 提示此方法预期为“String”,而看到了“'''”。
,而且它看起来确实有点难看。
有更好的方法吗?
最佳答案
我相信 JSLint 认可的方法是在号码上调用 .toString()
:
var stringified = 1..toString();
// Note the use of the double .. to ensure the the interpreter knows
// that we are calling the toString method on a number --
// not courting a syntax error.
// You could also theoretically call 1["toString"];
关于javascript - JSLint 认可的将数字转换为字符串的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5821950/