Console Learner — An interactive JavaScript course.


1.5 Boolean Logic

>>>
true && false
false
The && operator is the logical AND of two boolean values.
>>>
true || aMissingVariable
true
The || operator is the logical OR. The second argument is not evaluated if the first is true.
>>>
!true
false
The ! operator is the logical NOT (negation).
>>>
false || "value"
"value"
Although the && and || operators coerce their operands to boolean values, they return the value of the last operand evaluated.
>>>
null || ""
""
The || operator thereby becomes a convenient way of setting a default value. But watch out for 0...
>>>
!!0
false
Using double negation, we force boolean type coercion. The undefined, null, 0, NaN and "" values are all false. Other values are true.
>>>
!!42
true
>>>
!!""
false
>>>
!!" "
true
>>>
!!({})
true
>>>

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.