Why does isNaN(” “) (string with spaces) equal false?

JavaScript interprets an empty string as a 0, which then fails the isNAN test. You can use parseInt on the string first which won’t convert the empty string to 0. The result should then fail isNAN.

Leave a Comment