rummykhan rummykhan - 1 year ago 118
Javascript Question

Why parseInt(key) === NaN always evaluates to false

I'm doing decision based on dictionary key, i have only two types of keys, numeric and alpha,

var _dict = { 'a':'one', 'b':'two', '1':'three' };

$.each( _dict, function( key, value ){

if( parseInt( key ) === NaN ) {

// this statement always evalute to false

} else {



if i print
, it will also return

I alreay found the solution from this question javascript parseInt return NaN for empty string

But i was wondering why it always evaluates to false.

Answer Source

That's because NaN is defined to be not equal to anything (including itself). Check it:

>> NaN === NaN

You should use isNaN() function instead:

>> isNaN(NaN)
>> isNaN(0/0)
>> isNaN(parseInt('a'))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download