Logical AND Operator (&&) (JavaScript)

Performs a logical conjunction on two expressions.

Syntax


result = expression1 && expression2   

Parameters

result
Any variable.

expression1
Any expression.

expression2
Any expression.

Remarks

If expression1 evaluates to false, result is expression1. Otherwise, result is expression2. Consequently, the operation returns true if both operands are true; otherwise, it returns false.

JavaScript uses the following rules for converting non-Boolean values to Boolean values:

  • All objects are considered to be true.

  • Strings are considered to be false if they are empty.

  • null and undefined are considered to be false.

  • A Number is false if it is zero.

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

See Also

Operator Precedence
Operator Summary (JavaScript)