You could use something simple as Math.max(5, 10);

const numOne = 5;
const numTwo = 10;

console.log(`Bigger number is: ${Math.max(numOne, numTwo)}`);

Or if you absolutely 'have to' use switch statement, you can try something like this:

const numOne = 5;
const numTwo = 10;

switch(true) {
    case (numOne > numTwo):
        console.log(`Bigger number is ${numOne}`);
        break;
    case (numOne < numTwo):
        console.log(`Bigger number is ${numTwo}`);
        break;
    case (numOne === numTwo):
        console.log(`${numOne} is equal to ${numTwo}`);
        break;
     default: console.log(false, '-> Something went wrong');
}

Answer from Dženis H. on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › maximum-of-two-numbers-in-javascript
Maximum of Two Numbers in JavaScript - GeeksforGeeks
July 23, 2025 - The conditional operator, also ... JavaScript. It takes three operands: a condition followed by a question mark (?), an expression to evaluate if the condition is true, and a colon (:) followed by an expression to evaluate if the condition is false. ... Example: Finding maximum of two numbers using the ...
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-max-of-two-numbers
Get the Max of two Numbers using JavaScript | bobbyhadz
You can imagine that the function got called with multiply, comma-separated arguments with the help of the spread syntax (...). If the Math.max() function gets called with a value that is not a number, the function attempts to convert the value to a number before making the comparison. Note that some non-numeric values get converted to valid numbers in JavaScript. Here are some examples.
🌐
Medium
medium.com › @amirakhaled2027 › how-to-find-the-largest-of-two-numbers-in-javascript-6fac783be845
How to find the largest of two numbers in JavaScript - Amira Khaled - Medium
August 25, 2024 - How to find the largest of two numbers in JavaScript To find the largest of two numbers in JavaScript, you can use the Math.max() function. Here's an example: var number1 = 10; var number2 = 5; var …
🌐
W3Schools
w3schools.com › jsref › jsref_max.asp
JavaScript Math max() Method
The Math.max() method returns the number with the highest value. ... Math.max() is an ECMAScript1 (JavaScript 1997) feature.
🌐
Cmu
jitsi.cmu.edu.jm › home › 7+ js: max of two numbers – quick tips!
7+ JS: Max of Two Numbers - Quick Tips!
February 12, 2025 - The function receives two numerical arguments and returns the larger of the two. If one or both arguments cannot be converted to a number, the function returns `NaN`. For example, `Math.max(25, 10)` will evaluate to 25.
🌐
TechOnTheNet
techonthenet.com › js › math_max.php
JavaScript: Math max() function
The third output to the console ... max() function to find the largest value in an array. ... In this example, the max() method returned 25 which is the largest value from the array called totn_array....
Top answer
1 of 14
71
The purpose of a function is that it can accept any value (like a number or a string) as an argument (the values inside parenthesis after the name) and perform operations on it. On the first line, you are declaring a function called max. function max(20,10){ // ... Inside of the parenthesis, there are 2 arguments. The problem is, these must be valid javascript identifiers (variables). They cannot start with a number (see http://www.w3schools.com/js/js_variables.asp). The first thing to do is change the arguments you define into valid js variables, like this: function max(a,b){ // ... (It doesn't matter much what you name them, since they are only used inside of this function and not in the global scope. In more complex programs it is beneficial to give more descriptive names.) Now that the function is ready to take in arguments (we'll do that last), we can create the logic inside of the function block using those arguments just like variables: function max(a, b) { if (a > b) { return a; } } Notice that we are using the same argument names that we defined in the first line, so the javascript interpreter knows we are referring to whatever was passed in to the function as an argument (not the literal letter "a"). Now this almost works, but what happens if b is greater than a? Nothing, so here we need to use more logic to cover all possible scenarios. function max(a, b) { if (a > b) { return a; } else { return b; } } Now, the function checks first if the first argument is greater, then returns (exits) if it is. If the first argument is not greater, then for the purposes of this exercise we can assume that the second argument is greater, so we return b. When you input this code into Team Treehouse's quiz box, they will test your code by calling the max() function with different arguments and checking the answers, like this: max(20,10) // => 20, CORRECT max(10,20) // => 20, CORRECT max(0,100) // => 100, CORRECT max(45,-45) // => 45, CORRECT
2 of 14
6
solution I used: script.js function max(a, b){ if (a>b){ return a; }else if (a==b){ return a; }else{ return b; }; }; console.log(max(2,3));
Find elsewhere
🌐
Tutorial Reference
tutorialreference.com › javascript › examples › faq › javascript-how-to-get-the-max-of-two-numbers
How to Get the Maximum of Two Numbers in JavaScript | Tutorial Reference
const num1 = 10; const num2 = 20; const maximum = Math.max(num1, num2); console.log(maximum); // Output: 20 // It works with any number of arguments console.log(Math.max(10, 20, 5, 30)); // Output: 30 // It also works with negative numbers console.log(Math.max(-10, -5)); // Output: -5 ... This ...
🌐
GeeksVeda
geeksveda.com › home › how to find a larger number of two numbers in javascript
How To Find a Maximum of Two Numbers in JavaScript
May 8, 2023 - ... function findMaxUsingMathMax(a, b) { return Math.max(a, b); } // Generate output with any two numbers console.log(Math.max(a, b)); ... This method uses the Math.max() method to find the maximum of the two numbers.
🌐
GitHub
gist.github.com › kosalvann › c62bc333cad7a0bfc209
Define a function max() that takes two numbers as arguments and returns the largest of them. Use the if-then-else construct available in Javascript. · GitHub
Define a function max() that takes two numbers as arguments and returns the largest of them. Use the if-then-else construct available in Javascript. - max.js
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-basic-exercise-34.php
JavaScript basic: Find the larger number from the two given positive integers - w3resource
// Define a function named max_townums_range using arrow function syntax with parameters x and y const max_townums_range = (x, y) => { // Check if x and y fall within the specified ranges using logical AND operators if (x >= 40 && x <= 60 && y >= 40 && y <= 60) { // Check if x is equal to y if (x === y) { return "Numbers are the same"; } else if (x > y) { return x; } else { return y; } } else { return "Numbers don't fit in range"; } }; // Log the result of calling max_townums_range with the arguments 45 and 60 to the console console.log(max_townums_range(45, 60)); // Log the result of calling
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript math.max() method
JavaScript Math.max() Method
September 1, 2008 - Following is the syntax of JavaScript Math.max() method − ... This method takes in a random number of parameters. The same is described below − · value1, value2, ... valueN: These are the numeric values for which we want to find the maximum. We can provide multiple values separated by commas. This method returns the largest of the provided numbers. In the following example, we are using the JavaScript Math.max() method to find the maximum among the provided negative numbers −
🌐
Reintech
reintech.io › blog › leveraging-math-max-method-tutorial
Leveraging the Math.max() Method | Reintech media
February 22, 2023 - Here is an example: let a = 10; let b = 15; let c = 20; let highestNum = Math.max(a, b, c); console.log(highestNum); // returns 20 · In this example, the highest number out of 10, 15, and 20 is 20, so that is what Math.max returns.
🌐
Programiz
programiz.com › javascript › library › math › max
JavaScript Math max()
The max() method takes in a random number of parameters: number1/number2/… - values among which the maximum number is to be computed ... // max() with positive numbers let numbers2 = Math.max(0.456, 135, 500); console.log(numbers2); // Output: // -1 // 500 · In the above example, we have ...
🌐
SheCodes
shecodes.io › athena › 1878-using-math-max-to-find-maximum-value-in-javascript
[JavaScript] - Using `Math.max()` to Find Maximum Value in | SheCodes
Learn how to use the JavaScript Math.max() method to find the largest of zero or more numbers. Understand how to use `Math.max.apply()` with an array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › max
Math.max() - JavaScript | MDN
The largest of the given numbers. Returns NaN if any of the parameters is or is converted into NaN. Returns -Infinity if no parameters are provided. Because max() is a static method of Math, you always use it as Math.max(), rather than as a method of a Math object you created (Math is not a constructor). Math.max.length is 2, which weakly signals that it's designed to handle at least two parameters.