We can use JavaScript functions to create blocks of code that perform particular tasks when called upon.
Let's take a look at an example to illustrate how functions work here in our script tags.
We've defined a function called my function
this function has two parameters A and B.
You can call your function anything you like.
The name can contain letters digits underscores in dollar signs the code to be executed inside the function
is placed within a set of curly brackets.
In this case the function is meant to output the value of a multiplied by B.
To do this we use a return statement.
It's important to note that a function will stop executing once it reaches the return statement.
The values of A and B are contained in our inner HCM l function.
In this case 8 into these values are known as arguments they define the values of the parameters inside
the function.
In this case A and B and you can see that we referred back to the function name as well before inserting
our arguments in the brackets.
We can see in our web browser that the arithmetic was performed is eight times two is sixteen.
One of the key benefits of functions is they can be used as many times as needed with different arguments
to produce different results.
For example to multiply different values in place of aid and to simply update the arguments.
Now we're multiplying 6 and 5 and you can see that the output is correct 30.