
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Program to find largest of three numbers - JavaScript
We are required to write a JavaScript function that takes in three or more numbers and returns the largest of those numbers.
For example: If the input numbers are −
4, 6, 7, 2, 3
Then the output should be −
7
Example
Let’s write the code for this function −
// using spread operator to cater any number of elements const findGreatest = (...nums) => { let max = -Infinity; for(let i = 0; i < nums.length; i++){ if(nums[i] > max){ max = nums[i]; }; }; return max; }; console.log(findGreatest(5, 6, 3, 5, 7, 5));
Output
The output in the console −
7
- Related Articles
- C++ Program to Find Largest Number Among Three Numbers
- Java Program to Find the Largest Among Three Numbers
- Swift Program to Find the Largest Among Three Numbers
- Haskell program to find the largest among three numbers
- Kotlin Program to Find the Largest Among Three Numbers
- C program to Find the Largest Number Among Three Numbers
- Java program to find largest of the three numbers using ternary operators
- Java program to Largest number among three numbers
- How to Find the Largest Among Three Numbers in the Golang program?
- How to Find the Largest Among Three Numbers using Python?
- Program to find largest product of three unique items in Python
- Java program to find maximum of three numbers
- Python program to find the maximum of three numbers
- C# program to find the maximum of three numbers
- Find the greatest product of three numbers in JavaScript

Advertisements