Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptAND(&&) Logical Operator in JavaScript

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.

Javascript




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

Javascript




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


Output:

true

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments