Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Logical AND (&&)

Logical AND: returns the first falsy value, or the last one.

Available since: ES1

Syntax

a && b

Examples

In conditions — both are true:

const age = 25;
const hasTicket = true;
 
console.log(age >= 18 && hasTicket);

Output:

true

Running an action only if a condition holds:

const user = { isAdmin: true };
 
user.isAdmin && console.log('Show admin panel');
console.log(0 && 'never');

Output:

Show admin panel
0

Notes

If the left side is falsy the right side is not evaluated. && binds tighter than ||: a || b && c means a || (b && c).

See also

In the tutorial

  • Logical operators — JavaScript logical operators — AND, OR, NOT, their precedence, default values with || and the ?? operator.

Thanks for reading!

Donate to the site — we work hard for you.