To get the maximum or minimum of two numbers in TypeScript, you can use the Math.max() and Math.min() functions respectively. Here are some examples:
Getting the maximum of two numbers:
const num1 = 10;
const num2 = 21;
const maxNum = Math.max(num1, num2);
console.log(maxNum); // Output: 21
Here,
Math.max() is used to find the greater value of num1 and num2.
Getting the minimum of two numbers:
const num1 = 10;
const num2 = 21;
const minNum = Math.min(num1, num2);
console.log(minNum); // Output: 10
Here,
Math.min() is used to find the smaller value of num1 and num2.