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
Operator Description Example
== Equal to: returns true if the operands are equal x == y
!= Not equal to: returns true if the operands are not equal x != y
=== Strict equal to: true if the operands are equal and of the same type x === y
!== Strict not equal to: true if the operands are equal but of different type or not equal at all x !== y
> Greater than: true if left operand is greater than the right operand x > y
>= Greater than or equal to: true if left operand is greater than or equal to the right operand x >= y
< Less than: true if the left operand is less than the right operand x < y
<= Less than or equal to: true if the left operand is less than or equal to the right operand x <= y
Javascript Logical Operators
&& Logical and
|| Logical or
! Logical not
//Logical Binary and Ternary Operators in Javascript
== Equal to
=== Strictly equal to
!= Not equal to
!== Strictly not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
&& Logical and
|| Logical or
! Logical not
? Ternary operator
const num = 6;
if (num <= 4 || num <= 8) {
console.log('true')
} else {
console.log('false')
}
//Expected output:true
// equal operator
console.log(2 == 2); // true
console.log(2 == '2'); // true
// not equal operator
console.log(3 != 2); // true
console.log('hello' != 'Hello'); // true
// strict equal operator
console.log(2 === 2); // true
console.log(2 === '2'); // false
// strict not equal operator
console.log(2 !== '2'); // true
console.log(2 !== 2); // false
if (age < 18) text = "Too young to buy alcohol";
<, >, <=, >=, ==, ===, !=, !==