-1

I know this sounds silly but I don't know why my min function is returning the max value instead of min value. Can someone please tell me here have I gone wrong?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    let findMin=(1,2);
    const resultOfMin=Math.min(findMin)
    document.write(resultOfMin);
    </script>
</body>
</html>
Nerdy19
  • 91
  • 4
  • 1
    Don't use the comma operator. If you want to store the arguments in a structure and then pass that to another function later, use an array and then spread it into the argument list when calling. `const arr = [1, 2]; Math.min(...arr)` – CertainPerformance Jun 03 '22 at 00:31
  • Some very basic debugging would have shown you that `findMin` was a number, not an array, and its value was 2, not [1,2]. – jarmod Jun 03 '22 at 00:40

0 Answers0