According to tutorial by w3schools (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_tostring_number), we can use toString()
method on a integer var. Kindly look at the following code:
var num = 15;
var n = num.toString();
alert(isNaN(n));
If toString()
method is working, why isNaN(n)
returning false
?
The
IsNaN
method tries converting the string passed to it back to a number, and since "15" is still actually a number, the method returnsfalse
.See: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/isNaN