Arguments in JavaScript

Example 1: Simple function without arguments.

Example 2: A function with 1 parameter and how to access using argument.

Example 3: A function with 2 parameter and how to access using argument.

Example 4: A function with 2 parameter and to find the number of parameters.

Example 5: To access parameters with for loop.

Example 6: Displays the contents and the output of the function.

Example 7: To know the type of document.
  1. <html>  
  2. <head >  
  3.     <title></title>  
  4. </head>  
  5. <body>  
  6.     <form id="form1">  
  7.     <div>  
  8.       
  9.     </div>  
  10.     </form>  
  11.     <script type="text/javascript">  
  12.         function Example1(arg)  
  13.         {  
  14.             document.write("Example1 :" + arg);  
  15.         }  
  16.         Example1("Sachin Tendulkar")  
  17.   
  18.         function Example2(arg) {  
  19.             document.write(" Example2 :" + Example2.arguments[0]);  
  20.         }  
  21.         Example2("Sachin Tendulkar ")  
  22.   
  23.         function Example3(arg1,arg2) {  
  24.             document.write(" Example3 :" + Example3.arguments[0] + " and " + Example3.arguments[1]+" are great");  
  25.         }  
  26.         Example3("Sachin Tendulkar""Saurav Ganguly");  
  27.   
  28.         function Example4(arg1, arg2) {  
  29.             document.write("Length:"+arguments.length);  
  30.         }  
  31.        Example4("Sachin Tendulkar""Saurav Ganguly")  
  32.   
  33.         function Example5() {  
  34.             document.write("Length:" + arguments.length);  
  35.         }  
  36.         Example5("Sachin Tendulkar""Saurav Ganguly")  
  37.   
  38.         function Example6() {  
  39.             for (var i = 0; i < arguments.length;i++) {  
  40.                 document.write(arguments[i]+" ");  
  41.             }  
  42.               
  43.         }  
  44.         Example6("Sachin Tendulkar""Saurav Ganguly")  
  45.   
  46.         function Example7() {  
  47.             document.write(":" + arguments[0]);  
  48.             document.write(":" + arguments[1]);  
  49.         }  
  50.         Example7("Sachin Tendulkar""Saurav Ganguly");  
  51.   
  52.         function Example8() {  
  53.             arguments[0]="Kaushik";  
  54.             document.write(":" + arguments[0]);  
  55.             document.write(":" + arguments[1]);  
  56.         }  
  57.         Example8("Sachin Tendulkar""Saurav Ganguly");  
  58.   
  59.         function Example9()  
  60.         {  
  61.             var sum = 0;  
  62.             for (var i = 0; i < 5; i++) {  
  63.                 sum = sum + i;  
  64.             }  
  65.             document.write("output: "+sum+" :");  
  66.             document.write(arguments.callee);  
  67.         }  
  68.        Example9();  
  69.   
  70.         function Example10() {  
  71.             document.write(typeof arguments)  
  72.         }  
  73.         Example10();  
  74.   
  75.   
  76.     </script>  
  77. </body>  
  78. </html>