Question: WRITE A CODE TO FIND LARGEST NUMBER IN ARRAY

function findLargestNumber(array) { // Function definition to find the largest number in an array if (array.length === 0) { // Check if the array is empty return "Array is empty"; // Return a message if the array is empty } let largest = array[0]; // Initialize a variable to store the largest number, assuming the first element is the largest for (let i = 1; i < array.length; i++) { // Loop through the array starting from the second element if (array[i] > largest) { // Compare the current element with the largest number found so far largest = array[i]; // If the current element is larger, update the largest number } } return largest; // Return the largest number found in the array } // Example usage: const numbers = [10, 40, 5, 30, 25]; // Array of numbers console.log("Largest number:", findLargestNumber(numbers)); // Output the largest number found in the array

Output: