JS Dasar: 50. Function anonymous

by istiq20

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Function anonymous</title>
  </head>
  <body>
    <script>
      // anonymous function di variabel
      const say = function (name) {
        document.writeln(`<p>Hello ${name}</p>`);
      };

      say("Eko");
      say("Budi");

      // anonymous function di parameter
      function giveMeName(callback) {
        callback("Eko");
      }

      giveMeName(say);

      giveMeName(function (name) {
        document.writeln(`<p>Hi ${name}</p>`);
      });

      giveMeName(function (name) {
        document.writeln(`<p>Hi ${name}</p>`);
      });

      giveMeName(function (name) {
        document.writeln(`<p>Hi ${name}</p>`);
      });
    </script>
  </body>
</html>