David David - 10 months ago 36
Javascript Question

Why isn't undefined less than 1?

So in most cases I've been able to use something similar to these lines, but Javascript has given me this weird result.

If I take some value and it turns out to be undefined, when compared to an integer, it does not appear to be less than or greater than any number. Why is this?

if(undefined < 1 || undefined >= 1)

//this always alerts no



There is no operator '<' can not be applied to type 'undefined' error in JavaScript as you would find in other typed languages. As such, JavaScript evaluates incompatible types with an operator to false.