Console Learner — An interactive JavaScript course.


1.6 Numeric Comparison

>>>
1 < 1
false
The ==, !=, <, <=, > and >= numeric comparison operators work as expected...
>>>
42 <= 42
true
>>>
4711 >= "4711"
true
Numeric comparison will coerce both operands to numbers.
>>>
NaN == NaN
false
The special NaN (Not A Number) value behaves in a different way.
>>>
isNaN(NaN)
true
Using the built-in isNaN function, this special case can be checked.
>>>
+ "  42  "
42
With the unary prefix + operator, any value can be coerced into a number.
>>>
+ null
0
Some results might be expected...
>>>
+ undefined
NaN
...but others not so much
>>>

The console allows you to interact with the course material and examples. Use the following keys:

A special logging function is also available:


Need more magic? Check out the other developer tools on this site.