In JavaScript, Math.min() is a built-in function used to find the minimum value among the numbers passed as arguments. It can accept any number of arguments, and it returns the smallest of those values.
Example:
let numbers = [5, 8, 3, 12, 4]; let minNumber = Math.min(...numbers); console.log(minNumber); // Output: 3
In this example:
- We have an array 'numbers' containing [5, 8, 3, 12, 4].
- We use the spread syntax ('...') to pass each element of the array as an individual argument to 'Math.min()'.
- Math.min() returns the smallest value among the elements of the array, which is '3'.
Note: If Math.min() is called with no arguments or with non-numeric values, it returns 'Infinity'. Additionally, Math.min() doesn't work directly with arrays, so we need to use the spread syntax or other techniques to pass the array elements as arguments.