|Logical AND (&&)|
The logical AND operator && (don't confuse it with the Bitwise AND Operator & that works on the binary representation of its integer operands) works with boolean expressions (boolean expressions are those expressions that produces a boolean value; most of the time, you will perform that using the comparison operators) to produce a boolean value. When both of the boolean operands evaluate to true, the logical AND operator returns the value true. It's much more like saying if the right operand is true AND if the left operand is true, then return true. Note that if one of them evaluates to false, the logical AND operator returns false.
This operator is called a short circuit operator, which means that if the Interpreter produces the boolean value false from the left operand, it doesn't evaluate the right operand. Remember, AND produces true only if both of its operands evaluate to true. Why would we need to evaluate the second (right) operand if the first (the left) operand evaluates to false (because AND will produce false even if the second operand evaluates to true as long as the first evaluated to false)? If the left operand evaluates to true, the interpreter evaluates the right operand.
This is a somewhat advanced topic for you now, so we will discuss it more fully in another article. Note that we have said that true is equal to 1 and false is equal to 0, so we could write both the operands to evaluate to 1 or 0, and the interpreter will understand them as true or false with the logical AND operator, so the statement
var x = 1 && 0; // produces the value 0
var x = 1 && 1; // produces the value 1
var x = 0 && 1; // produces the value 0
|Logical OR |
The logical OR operator || (don't confuse it with the Bitwise OR Operator | that works on the binary representation of its integer operands) works with boolean expressions to produce a boolean value. When any of the boolean operands evaluates to true, the logical OR operator produces the value true. It's like saying if the first operand evaluates to true OR the second operand evaluates to true, produce the value true.
This operator is also a short circuit operator, but it makes the interpreter behave differently from the way it behaves with the && operator. With the Operator || the interpreter evaluates the first (left) operand; if it evaluates to true, it produces the value true and escapes the evaluation of the second (right) operand. This makes sense because the || operator evaluates to true if any of its operands are true; we don't need to evaluate the second operand if the first has evaluated to true. The short circuit operation saves the interpreter time. (In a future article I will show you the difference between the Full Evaluation and Short Circuit). Since the interpreter understands 1 as true and 0 as false:
var x = 1 || 0; // produces the value 1
var x = 1 || 1; // produces the value 1
var x = 0 || 0; // produces the value 0