A Function Can Be Set Up to Accept a Variable Number of Arguments : Function : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » Function »

 

A Function Can Be Set Up to Accept a Variable Number of Arguments



<html>
<head>
  <title>A Function Can Be Set Up to Accept a Variable Number of Arguments</title>
  <script type="text/javascript">
  <!--
    function welcomeMessage(userName) {
      if (userName != null) {
        document.writeln("Hello, " + userName);
      }else{
        document.writeln("Welcome to our Web site!");
      }
      numArgs = welcomeMessage.arguments.length;
      if(numArgs > 1) {
        for(var i = 1; i < numArgs; i++) {
          document.writeln("""+welcomeMessage.arguments[i]+""");
        }
      }
    }
  // -->
  </script>
</head>
<body>
  <script type="text/javascript">
  <!--
    var userName = "David", extraMsg = "It has been a long time!";
    var userName2 = null;
    var extraMsg1 = "Would you like to become a member?";
    var extraMsg2 = "You can enroll online!";
    welcomeMessage(userName, extraMsg);
    document.writeln("<hr>");    welcomeMessage(userName2, extraMsg1, extraMsg2);
  // -->
  </script>
</body>
</html>


           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» Function