In TypeScript, we can compare numbers using comparison operators which are:
- < (less than)
- > (greater than)
- <= (less than or equal to)
- >= (greater than or equal to)
- == (equal to)
- != (not equal to)
- === (strict equal to)
- !== (strict not equal to)
Here are some examples of comparing numbers in TypeScript:
let a: number = 10;
let b: number = 5;
// less than
console.log(a < b); // false
// greater than
console.log(a > b); // true
// less than or equal to
console.log(a <= 10); // true
// greater than or equal to
console.log(b >= 5); // true
// equal to
console.log(a == 10); // true
// not equal to
console.log(b != 10); // true
// strict equal to
console.log(a === 10); // true
// strict not equal to
console.log(b !== 5); // false
In the above example, we have declared two variables a and b of number type and compared them using different comparison operators.