[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/Logical_AND [Back]  [Original]

(&&) - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

(&&)

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

(&&) () Boolean true , true. false.

, , , .

In this article

const a = 3;
const b = -2;

console.log(a > 0 && b > 0);
// Expected output: false

js
expr1 && expr2;

(&&) , ; , .

true, (truthy). false, (falsy).

, false:

  • false;
  • null;
  • NaN;
  • 0;
  • ("", '', ``);
  • undefined.

:

js
result = "" && "foo"; // result is assigned "" (empty string)
result = 2 && 0; // result is assigned 0
result = "foo" && 4; // result is assigned 4

, && , , , . ( ) , Boolean.

. , false, . .

.

( ) &&  

( ) , . , . :

js
function A() {
  console.log("  A");
  return false;
}
function B() {
  console.log("  B");
  return true;
}

console.log(A() && B());
//     A,     "  A",
//   &&   false ( A  false),      false;
//          B

, , && || (. ).

js
false || (true && true); //  true
true && (false || false); //  false
2 == 3 || (4 < 0 && 1 == 1); //  false

&& ( ).

js
a1 = true && true; // t && t  true
a2 = true && false; // t && f  false
a3 = false && true; // f && t  false
a4 = false && 3 == 4; // f && f  false
a5 = "Cat" && "Dog"; // t && t  "Dog"
a6 = false && "Cat"; // f && t  false
a7 = "Cat" && false; // t && f  false
a8 = "" && false; // f && f  ""
a9 = false && ""; // f && f  false

:

js
bCondition1 && bCondition2;

:

js
!(!bCondition1 || !bCondition2);

:

js
bCondition1 || bCondition2;

:

js
!(!bCondition1 && !bCondition2);

, .

:

js
bCondition1 || (bCondition2 && bCondition3);

, :

js
bCondition1 || (bCondition2 && bCondition3);

Specification
ECMAScript 2027 LanguageSpecification
# prod-LogicalANDExpression


Web Proxy Viewer  |  New URL  |  Original Page