根据 w3schools ( http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_tostring_number ) 的教程,我们可以在整数变量上使用 toString()
方法。请看下面的代码:
var num = 15;
var n = num.toString();
alert(isNaN(n));
如果toString()
方法有效,为什么isNaN(n)
返回false
?
最佳答案
IsNaN
方法尝试将传递给它的字符串转换回数字,并且由于“15”实际上仍然是一个数字,因此该方法返回 false
.
参见:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/isNaN
关于javascript - 在javascript中将数字转换为字符串的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30775709/