In JavaScript, you can compare numbers using comparison operators. Here are the comparison operators available in JavaScript:
* > - greater than
* < - less than
* >= - greater than or equal to
* <= - less than or equal to
* == - equal to (checks value only)
* != - not equal to (checks value only)
* === - equal to (checks both value and data type)
* !== - not equal to (checks both value and data type)
Example 1: Greater than comparison
const a = 5;
const b = 3;
console.log(a > b); // Output: true
Example 2: Less than comparison
const x = 10;
const y = 20;
console.log(x < y); // Output: true
Example 3: Greater than or equal to comparison
const m = 15;
const n = 20;
console.log(m >= n); // Output: false
Example 4: Less than or equal to comparison
const p = 10;
const q = 10;
console.log(p <= q); // Output: true
Example 5: Equal to comparison (checking value only)
const r = 10;
const s = "10";
console.log(r == s); // Output: true
Example 6: Not equal to comparison (checking value only)
const t = 7;
const u = "10";
console.log(t != u); // Output: true
Example 7: Equal to comparison (checking both value and data type)
const v = 10;
const w = "10";
console.log(v === w); // Output: false
Example 8: Not equal to comparison (checking both value and data type)
const x = 10;
const y = "10";
console.log(x !== y); // Output: true
These are some of the ways to compare numbers in JavaScript using ECMAScript 2021.