JS OOP: 27. Error

by istiq20

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Error</title>
  </head>
  <body>
    <script>
      class MathUtil {
        static sum(...numbers) {
          if (numbers.length === 0) {
            throw new Error("Total parameter harus lebih dari 0");
          }

          let total = 0;
          for (const number of numbers) {
            total += number;
          }
          return total;
        }
      }

      // jika parameternya kosong
      console.info(MathUtil.sum()); // Error: Total parameter harus lebih dari 0
      console.info("Eko");

      const result = MathUtil.sum(1, 1, 1, 1, 1);
      console.info(result);
    </script>
  </body>
</html>