Computer >> Computer tutorials >  >> Programming >> Javascript

What are function parameters in JavaScript?


With JavaScript, you can 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 a comma. 

Example

You can try to run the following code to learn how to add parameters to JavaScript functions −

<html>
   <head>
      <script>
         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('John', 27)" value = "Details">
      </form>
   </body>
</html>