You can find the largest among three numbers using the if...else statement.
Example 1: Largest Number Among Three Numbers
Output
Enter first number: -7 Enter second number: -5 Enter third number: -1 The largest number is -1
In the above program, parseFloat() is used to convert numeric string to number. If the string is a floating number, parseFloat() converts the string into floating point number.
The numbers are compared with one another using greater than or equal to >= operator. And the if...else if...else statement is used to check the condition.
Here, logical AND && is also used to check two conditions.
You can also use the JavaScript built-in Math.max() function to find the largest among the numbers.
Example2: Using Math.max()
Output
Enter first number: 5 Enter second number: 5.5 Enter third number: 5.6 The largest number is 5.6
Math.max() returns the largest number among the provided numbers.
You can use Math.min() function to find the smallest among the numbers.