1
00:00:00,120 --> 00:00:07,560
We can use JavaScript functions to create blocks of code that perform particular tasks when called upon.

2
00:00:07,580 --> 00:00:12,650
Let's take a look at an example to illustrate how functions work here in our script tags.

3
00:00:12,650 --> 00:00:15,440
We've defined a function called my function

4
00:00:18,480 --> 00:00:21,880
this function has two parameters A and B.

5
00:00:22,080 --> 00:00:24,570
You can call your function anything you like.

6
00:00:24,630 --> 00:00:34,380
The name can contain letters digits underscores in dollar signs the code to be executed inside the function

7
00:00:34,650 --> 00:00:37,990
is placed within a set of curly brackets.

8
00:00:38,010 --> 00:00:44,790
In this case the function is meant to output the value of a multiplied by B.

9
00:00:45,090 --> 00:00:48,480
To do this we use a return statement.

10
00:00:48,480 --> 00:00:56,460
It's important to note that a function will stop executing once it reaches the return statement.

11
00:00:56,460 --> 00:01:02,950
The values of A and B are contained in our inner HCM l function.

12
00:01:03,060 --> 00:01:11,640
In this case 8 into these values are known as arguments they define the values of the parameters inside

13
00:01:11,640 --> 00:01:12,590
the function.

14
00:01:12,600 --> 00:01:20,670
In this case A and B and you can see that we referred back to the function name as well before inserting

15
00:01:20,730 --> 00:01:24,000
our arguments in the brackets.

16
00:01:24,150 --> 00:01:31,600
We can see in our web browser that the arithmetic was performed is eight times two is sixteen.

17
00:01:32,010 --> 00:01:37,770
One of the key benefits of functions is they can be used as many times as needed with different arguments

18
00:01:37,770 --> 00:01:39,990
to produce different results.

19
00:01:40,380 --> 00:01:47,550
For example to multiply different values in place of aid and to simply update the arguments.

20
00:01:47,550 --> 00:01:52,440
Now we're multiplying 6 and 5 and you can see that the output is correct 30.
