The sample code shows how to make a function which uses a parameter. A parameter is like a special variable which is used in a function to refer to a piece of data which is provided as input to the function. These pieces of data are also often called arguments.
The code below shows how to use just one argument. If you want to use more than one argument, see the sample code here. You can also watch the video which explains functions and parameters here.
<!DOCTYPE html> <html lang="en" <head> <meta charset="utf-8"/> <title>JavaScript - Functions with parameters</title> <script type="text/javascript"> /* functions can also use one or more parameters a parameter is like a special variable which is used in a function to refer to a piece of data which is provided as input to the function. These pieces of data are also often called arguments. */ // define the function and set the parameter eg. message function saymessage(message){ // function code goes here alert(message); } // call the function to be used and provide "Hello world" as an argument to the function. saymessage("Hello there"); </script> </head> <body> </body> </html> |