Reputation: 164
In the following code:
var notNum = 'dfsd'
Number(notNum) === NaN
The last expression evaluates to false. Do you know why? Is there no way to use NaN in a comparison?
typeof(Number(notNum)) === 'number'
This somehow evaluates to true. I really don't understand how NaN works..
Upvotes: 1
Views: 75
Reputation: 54
NaN (Not-a-Number) is a global object in JS returned when some mathematical operation gets failed.
You can't compare an object with another object directly. Either you have to use typeof which you are using or you can use Object.is()
Object.is(Number(notNum), NaN) // true
Upvotes: 1