Wednesday, February 1, 2017

isNaN should perhaps be avoided

You use it like this right?

if (isNaN(whatever)) {

 
 

You'd think this would be truthy or falsey based on whether or not whatever was a number or not, but that's not so. Some strings will cause false to be returned from this thing, specifically strings that will survive the trip through a parseInt or a parseFloat. Also an empty string or a string with a single space looks to me like it will sail through with a false output based upon what I'm seeing on StackOverflow.

No comments:

Post a Comment