August 2016
Beginner to intermediate
847 pages
17h 28m
English
There are three operators, called logical operators, that work with Boolean values. These are:
! – logical NOT (negation)&& – logical AND|| – logical ORYou know that when something is not true, it must be false. Here's how this is expressed using JavaScript and the logical ! operator:
> var b = !true;
> b;
false
If you use the logical NOT twice, you get the original value:
> var b = !!true;
> b;
true
If you use a logical operator on a non-Boolean value, the value is converted to Boolean behind the scenes:
> var b = "one";
> !b;
false
In the preceding case, the string value "one" is converted to a Boolean, true, and then negated. The result of negating true is false. In the next example, there's a double negation, so the result is ...