SoFunction
Updated on 2025-03-03

Explanation of min function example in JS

Let's first look at the basic syntax of the min function

(value1,value2,...)

 

Value1, Value2,…: Value passed to the() function to find the minimum value.

Let's take a look at the specific examples below

The code is as follows

When parameters are positive and negative:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
</head>
<body>
<script type="text/javascript">
  ("Output : " + (10, 32, 2)); 
 ("Output : " + (-10, -32, -1));    
</script>
</body>
</html>

The execution results are as follows:

Output : 1
Output : -32

When no parameters are passed

The code is as follows:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
</head>
<body>
<script type="text/javascript">
 ("Output : " + ());    
</script>
</body>
</html>

The execution results are as follows

Output : -Infinity

When there are parameters in the parameters that cannot be converted to numbers:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
</head>
<body>
<script type="text/javascript">
  ("Output : " + (10,2,NaN));    
</script>
</body>
</html>

The execution results are as follows

Output : NaN