var a = {valueOf: function(){ if( ! this.i ) this.i = 0; this.i++; return this.i%2 ? NaN : 1; }} alert(isNaN(a) === isNaN(+a));