Logical Operators in JavaScript Language

Program to use Logical AND ( && ) Operators JavaScript Language


let a = 5;
let b = 10;
console.log(true && false);
console.log(true && true);
console.log(false && false);
console.log((a < b) && (a > b));

Output


false
true
false
false

Steps Description

  1. Declare two variables a and b
  2. Initialize both variables with value of 5 and 10 respectively a=5, b=10
  3. The function of the Logical AND && operator is to check two values, if both the values are true then it returns true otherwise it returns false.
  4. The values of a and b variables are displayed with the help of console.log inbuilt function

Program to use Logical OR ( || ) Operators JavaScript Language


let c = 10;
let d = 20;
console.log(true || false);
console.log(true || true);
console.log(false || false);
console.log((c < d) || (c > d));

Output


true
true
false
true

Steps Description

  1. Declare two variables c and d
  2. Initialize both variables with value of 10 and 20 respectively c=10, d=20
  3. The function of the logical OR || operator is to check two values, if either value is true, it will return true otherwise it will return false.
  4. The values of c and d variables are displayed with the help of console.log inbuilt function

Program to use Logical NOT ( ! ) Operators JavaScript Language


let e = 50;
let f = 100;
console.log(!(e == f));
console.log(!(e < f));
console.log(!true > true);
console.log(!false > false);
console.log(!true > false);

Output


true
false
false
true
false

Steps Description

  1. Declare two variables e and f
  2. Initialize both variables with value of 50 and 100 respectively e=50, f=100
  3. The function of Logical NOT ! operator is to check two values if the value is true then it will be false and if it is false then the value will be true.
  4. The values of e and f variables are displayed with the help of console.log inbuilt function