> How can I view if a variable has a numeric value using javascript?
> yeah yeah, whatever....
> if(typeOf(varname) == "number"
hehe, well actually you both missed the mark by a mile unless the original question was mis-stated.
"if a variable has a numeric value"
typeof() tests the type not the value B-)
function ( param){
if ( isNaN(param))
alert("Not a number value"
else
alert("Number value"
}
hey pete, i guess that you'll return false for a string which value is, say, "12"
sooooooooooooooo
the very proper way to check that is actually :
if (isNaN(parseInt(param, 10))) and then pete's code
where 10 is for the radix ;-)
Actually parseInt() should return NaN if it cannot obtain a valid number from the string... so it is likely that the functions use the same algorithm. The main difference is that parseInt() allows different radix input where isNaN can only be used directly on base 10, i.e.:
isNaN("B2" // true ( not a number )
isNaN(parseInt("B2", 16)); // false ( is a number)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.