Friday, 14 July 2023

Function Parameters in JavaScript

Function Parameters in JavaScript
In previous post we have seen functions without parameters. But there is a facility to pass different parameters while calling a function. These passed parameters can be captured inside the function and any manipulation can be done over those parameters. A function can take multiple parameters separated by comma.
Example
<html>
   <head>
      <script type="text/javascript">
         function sayHello(name, age)
         {
            document.write (name + " is " + age + " years old.");
         }
      </script>
   </head>
   <body>
      <p>Click the following button to call the function</p>
      <form>
         <input type="button" onclick="sayHello('Aman', 7)" value="Say Hello">
      </form>
      <p>Use different parameters inside the function and then try...</p>
   </body>
</html>
Output
Click the following button to call the function
Use different parameters inside the function and then try...

0 comments

Post a Comment