Jasyn Marais

Comparison Operators

14 February 2023

In JavaScript, comparison operators are used to compare values and return a Boolean result (true or false) based on the comparison. There are several comparison operators in JavaScript, including:

Here are some examples of using comparison operators in JavaScript:

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

In this example, we declare two variables, a and b, and then use various comparison operators to compare them and other values. The result of each comparison is a Boolean value (true or false), which is then logged to the console using console.log().