PART I: AT THE GATES OF ENLIGHTENMENT
1.12 Logical Operators
And: &&, Or: ||, Not: !
With && both operands need to be Boolean true in order to get a true output.
because true and true is true.
because false and true is false.
The two vertical bars denote an OR logical operator. In US Windows you can access the || by pressing SHIFT and the last key on the right at the row starting with qwerty.
With logical or ||, one of the operands needs to be true in order to get a Boolean true as the output.
Boolean false, the number zero, the value known as undefined, and the value known as null which we haven’t covered yet.
Let me declare a few variables and values in order to do some tests:
var x = 3;
var y = 0;
var z = "Tony";
Based on my first statement, is variable x true or false? It is true because it has a value. On the other hand, variable y is false.
Boolean(x); <-- the statement is true (since our x from the previous examples is 3)
Boolean(!x); <-- the statement is false (since x has a value, !x is a false statement)
Boolean(y); <-- the statement is false (y is 0 and zero is false )
Boolean(!y); <-- the statement is true (since y is 0, !y is a true statement)
Boolean(z); <-- the statement is true (z is "Tony" and Tony is true)
Boolean(!z); <-- the statement is false (since z has a value, the !z statement is false)
Boolean(a); <-- the statement is false (a is undefined and we can’t say it is true)
Boolean(!a); <-- the a statement is true (since a is undefined, !a is a true statement)
Let’s do some lab work to review all these concepts.