# How do i check for "NaN"

**URL:** <https://forum.kirupa.com/t/how-do-i-check-for-nan/156001>\
**Category:** Uncategorized\
**Created:** [July 21, 2005, 8:15pm UTC](https://forum.kirupa.com/t/how-do-i-check-for-nan/156001 "2005-07-21T20:15:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)\
**Post date:** [July 21, 2005, 8:15pm UTC](https://forum.kirupa.com/t/how-do-i-check-for-nan/156001/1 "2005-07-21T20:15:40Z")

</div>

I’ve got to write to a db table (using Zinc) and the field requires a data type of Number. In my application, the user enters a string, which could be letters in which case I’ll throw an error.

So far, im using Number(a) to convert to a number, but if the string wasn’t a number, I of coarse get “NaN”.

But how do i do a conditional that checks for NaN?

b = Number(a)

if(b == NaN) …this doesn’t work  
if(b == “NaN”) also doesn’t work nor does  
if(b == Number.NaN)

Maybe theres a better way to check for a number, if so, please let me know

Thanks!
