Javascript - Operator Boolean AND

Introduction

The logical AND operator is && and is applied to two values:

var result = true && false; 

Logical AND behaves as the following truth table:

Operand 1 Operand 2Result
truetrue true
truefalsefalse
false true false
false falsefalse

Logical AND can be used with any data types, not just Boolean values.

When either operand is not a primitive Boolean, logical AND does not always return a Boolean value.

It uses the following rules:

first AND second Result
the first operand is an object the second operand is always returned.
the second operand is an objectthe object is returned only if the first operand evaluates to true.
both operands are objects the second operand is returned.
If either operand is null null is returned.
If either operand is NaN NaN is returned.
If either operand is undefinedundefined is returned.

The logical AND operator is a short-circuited operation.

If the first operand determines the result, the second operand is never evaluated.

If the first operand is false, the result is false.