Why is Nan bigger than any number?

Asked

Viewed 103 times

3

A practical example of this statement is:

parseInt(50) > parseInt('a');

When running this operation on a console, for example, the result is false. The real code that brought me to this question is similar to this:

variableB = parseInt(jQuery('some-element').html());
if(parseInt(variableA) > variableB)
     // Faça isso.
else
     // Faça outra coisa.

Sometimes the some-element will not be filled with anything at all, causing the value of variableB was NaN. But how some-element was not filled with anything, I would like it to be evaluated as if it had been filled with 0. That is, if variableA is a positive greater than 0, the comparison should return true.

  • You could put a condition with Nan or just an 'e' in if

  • Question in English OS -> http://stackoverflow.com/questions/26982881/why-nan-is-greater-than-any-number-in-javascript

  • It would not be good to put the link reference in the question itself?

1 answer

4

Browser other questions tagged

You are not signed in. Login or sign up in order to post.