Open In App

AND(&&) Logical Operator in JavaScript

JavaScript Logical And(&&) Operator or Logical Conjunction Operator operates on a set of operands and returns true only if all the operands are true otherwise returns false. It operates the operands from left to right and returns false whenever the first falsy value is encountered.

The Logical AND(&&) Operator can also be used on non-boolean values also. AND operator has higher precedence than the OR operator.



Syntax:

a&&b

Example 1: In this example, we will use the AND operator on normal values.






console.log(true && false);
console.log(true && true);
console.log(1 && 0);
console.log(1 && 2);
console.log("1" && true);
console.log("0" && true);

Output:

false
true
0
2
true
true

Example 2: In this example, we will use the AND operator on function calls




function a () {
    return true;
}
function b () {
    return true;
}
  
console.log(a() && b());

Output:

true

Supported Browsers:

We have a complete list of JavaScript Logical Operators, to learn about those please go through JavaScript Logical Operator article.

Article Tags :