The Math.min() function is used to return the lowest-valued number passed in the function.
The Math.min() function returns NaN if any parameter isn’t a number and can’t be converted into one.
min() is a static method of Math, therefore, it is always used as Math.min(), rather than as a method of a Math object created.
Syntax:
Math.min(value1, value2, ...)
Parameters Used:
Value1,Value2 :Values sent to math.min() function for finding the lowest-valued number.
Return Value:
The Math.min() function returns the smallest of the given numbers.
Examples:
Input : Math.min(10, 32, 2) Output : 2 Input : Math.min(-10, -32, -1) Output : -32 Input : Math.min() Output : -Infinity Input : Math.min(10,2,NaN) Output : NaN
- When positive numbers are passed as parameters.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.min(10, 32, 2));
</
script
>
Output:
Output : 2
- When negative numbers are passed as parameters.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.min(-10, -32, -1));
</
script
>
</
div
>
Output:
Output : -32
- When no parameters are passed.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.min());
</
script
>
Output:
Output : -Infinity
- When NaN is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.min(10,2,NaN));
</
script
>
Output:
Output : NaN
leave a comment
0 Comments