JavaScript && Logical AND Operator
The logical AND operator (&&) returns the first falsy value, or the last value if all are truthy. In conditions it means both must be true.
Description
The logical AND operator && is true in a condition only when both operands are truthy. Strictly, it returns the first operand if that is falsy, otherwise the second, so it doesn't always return a boolean.
It short-circuits: if the left side is falsy, the right side isn't evaluated. That's why user && user.name doesn't throw when user is null, although optional chaining (user?.name) is now the clearer way to write it. && has higher precedence than ||.
Because it returns one of its operands rather than a boolean, && is used in frameworks such as React to render something only when a condition holds, {isLoggedIn && <Menu />}. Watch out for numbers: 0 && anything returns 0, which may be shown on screen. Converting the condition to a boolean, count > 0 && ..., avoids that.
Properties
- Operator
&&- Category
- Logical
- Precedence
- 4 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
x && yExample
Browser Support
The following information will show you the current browser support for the && operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





