Logical AND

The logical AND operator is &&.

 
var result = true && false;
  

Logical AND behaves in the following truth table:

OPERAND 1OPERAND 2RESULT
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse

Logical AND can work on any type of operand, not just Boolean values.

When logical AND working with non-Boolean values:

OPERAND 1OPERAND 2RESULT
objectany valuereturn the second operand
and valueobjectreturn the second object if the first operand evaluates to true.
objectobjectreturn the second operand
nullany valuenull
any valuenullnull
NaNany valueNaN
any valueNaNNaN
undefinedany valueundefined
any valueundefinedundefined

Short-circuited operation

The logical AND operator is a short-circuited operation. The short-circuited operation means that if the first operand determines the result, the second operand is not evaluated. For logical AND, if the first operand is false, the second operand is not evaluated since the result is false.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var found = false; 
        var i = 1;
        var result = (found && i++); 
        document.writeln(result); //false
        document.writeln(i); //1
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Language Basics  

Operators:
  1. JavaScript Operators
  2. Increment/Decrement Operators
  3. Increment/Decrement Operators for String, Boolean, Floating-point and Object
  4. Unary Plus and Minus
  5. Bitwise Not operator
  6. Bitwise AND
  7. Bitwise OR
  8. Bitwise XOR
  9. Left Shift
  10. Signed Right Shift
  11. Unsigned Right Shift
  12. Logical NOT
  13. Logical AND
  14. Logical OR
  15. Multiply
  16. Divide
  17. Modulus
  18. Add
  19. Subtract
  20. Relational Operators
  21. Equal and Not Equal
  22. Identically Equal and Not Identically Equal
  23. Conditional Operator
  24. Assignment Operators
  25. Comma Operator