The reason isNaN(Infinity)
returns false
has nothing to do with mathematical technicalities, it's simply because its implementation is equal to this:
function isNaN(object) {
var coerced = +object;
return coerced !== coerced;
}
In other words, it coerces the input to a Number
. If the coerced value is determined to be NaN
(by checking if it is not strictly equal to itself), then it returns true
. Otherwise it returns false
.
[Infinity, null, undefined, true, new Date(), {}, [], [1], [1,2,3], 'blah', '4'].forEach(function (object) {
console.log('object: ' + (typeof object !== 'number' ? JSON.stringify(object) : object));
console.log('coerced: ' + (+object));
console.log('isNaN: ' + isNaN(object));
console.log('==================');
});