javascript logical operator code example

Example 1: not operator js

let a = true;

let b = !a;

console.log(b); //output: false

Example 2: js logical operators

Javascript Logical Operators
&& Logical and
|| Logical or
! Logical not

Example 3: or operator javascript

//|| is the or operator in JavaScript
if(a == 1 || b != 'value'){
    yourFunction();
}

Example 4: or operator javascript

var a = 2;
var b = 5;
var c = 10;

if (a === 3 || a === 2) {
	console.log("TRUE");
} else {console.log("FALSE");}
if (a === 4 || b === 3 || c === 11) {
	console.log("TRUE");
} else {console.log("FALSE");}
if (b === 5 || c != 10) {
	console.log("TRUE");
} else {console.log("FALSE");}

/* Output:
TRUE
FALSE
TRUE
*/

Example 5: and javascript

let a = 1;
let b = -1;

if (a > 0 & b > 0){
	console.log("and");
} else if (a > 0 || b > 0){
	console.log("or");
}

Example 6: js comparison operators

Javascript Comparison Operators
== Equal to
=== Equal value and equal type
!= Not equal
!== Not equal value or not equal type
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
? Ternary operator

Tags:

Php Example