Find the largest number in an array:
let numbers = [42, 17, 89, 23, 56]
let max = numbers[0] // Start with first element
for (let num of numbers) {
if (num > max) {
max = num
}
}
console.log(`Maximum: ${max}`) // 89
Starting with the first element (not ) handles negative numbers correctly.