B
B
bormor2016-07-20 16:33:45
JavaScript
bormor, 2016-07-20 16:33:45

JavaScript Type Casting: Why does 99 > 'string' convert to false?

It seems that the data should be converted to a number:
99 > 'string'
99 > NaN
99 > 0
true
But the code for testing the hypothesis returns false

if (99 > 'строка'){
  console.log('True');
} else{
  console.log('False')
}

Where am I wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Maslakov, 2016-07-20
@bormor

// parseInt('string') is NaN
// 99 > NaN is false

That is, any comparison operations with NaN will return false. Use the isNaN(...) function.
And what do you say when
NaN === NaN // is false

A
Alex, 2016-07-20
@streetflush

And why is it suddenly NaN === 0?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question