Ember.typeOf and NaN

I noticed earlier that Ember.typeOf(NaN) === 'number'. Is this expected behavior? I know that the Javascript typeof operator does that, but I thought the typeOf function was supposed to clear up some of those inconsistencies. For me, I would assume that if typeOf returns 'number', I would be able to use the object in a numerical computation safely, which obviously isn’t the case.

NaN is a primitive Number value, and the Ember.typeOf doc says 'number' represents “Number primitive or Number object”.

The current behaviour means Ember.typeOf(parseInt(someValue)) always yields the same result, although I don’t have an example where this would be useful.

So, I second your question. Ember.typeOf returns 'null' and 'undefined' where appropriate, so I think it would be consistent for Ember.typeOf(NaN) === 'NaN', since this method gives finer distinctions to the types it detects.

1 Like