WEBVTT

1
00:00:00.320 --> 00:00:02.580
Hi and welcome to the
JavaScript Video course.

2
00:00:02.610 --> 00:00:05.300
In this lesson we'll be
exploring arrow functions.

3
00:00:05.330 --> 00:00:08.900
Arrow functions are a new way
to declare functions in JavaScript.

4
00:00:08.930 --> 00:00:14.700
They are shorter, more concise and provide
a new way to handle this keyword.

5
00:00:14.730 --> 00:00:17.300
For example, let's consider the following

6
00:00:17.330 --> 00:00:23.540
code. Let's clean up our file and let's
create function myFunction

7
00:00:23.570 --> 00:00:30.460
that takes in two arguments A
and B and outputs their sum.

8
00:00:30.490 --> 00:00:33.260
We can rewrite the above function as

9
00:00:33.290 --> 00:00:40.900
an arrow function as follows. const
myArrowFunction

10
00:00:40.930 --> 00:00:48.420
it will take in arguments A and B
and it will return their sum.

11
00:00:48.450 --> 00:00:50.900
So let's run these functions.

12
00:00:50.930 --> 00:00:54.420
Let's say we run my function with one

13
00:00:54.450 --> 00:01:02.460
and two and my arrow function with one
and two and let's console log the results

14
00:01:02.490 --> 00:01:08.540
and run this and we see that both
of them give us the value of three.

15
00:01:08.570 --> 00:01:11.290
You can rewrite the arrow function

16
00:01:11.320 --> 00:01:18.920
in a shorter way,
which would just be like this.

17
00:01:20.080 --> 00:01:26.210
If we rerun this,
you will see three outputted again.

18
00:01:26.240 --> 00:01:30.060
So you would only do this if
you have a single statement.

19
00:01:30.090 --> 00:01:34.570
If you happen to have multiple statements
in your functions and there's multiple

20
00:01:34.600 --> 00:01:37.850
things that are happening,
you would still need to do this.

21
00:01:37.880 --> 00:01:41.740
And on other lines you can
write your other logic.

22
00:01:41.770 --> 00:01:43.700
If you have an arrow function with no

23
00:01:43.730 --> 00:01:48.460
arguments, then you have to specify
an empty pair of parentheses.

24
00:01:48.490 --> 00:01:51.700
Something like this for example:

25
00:01:51.730 --> 00:01:56.700
let's say this is random
function that returns three if you want

26
00:01:56.730 --> 00:02:00.260
to run this function actually,
let's make it return ten.

27
00:02:00.280 --> 00:02:03.020
If you want to run this function,
you would have to do this.

28
00:02:03.050 --> 00:02:05.460
So let's run this.

29
00:02:05.490 --> 00:02:09.820
And now we see ten as
well in our console log.

30
00:02:09.850 --> 00:02:11.380
These are just a few examples

31
00:02:11.400 --> 00:02:15.140
of the different arrow function syntaxes
and you will see them throughout this

32
00:02:15.170 --> 00:02:18.500
course and it is important that you
understand and recognize them.

33
00:02:18.530 --> 00:02:20.700
In conclusion, arrow functions are a great

34
00:02:20.730 --> 00:02:25.980
feature in JavaScript that allows us
to write cleaner, more concise code.

35
00:02:26.010 --> 00:02:28.120
Thanks for watching and have a great day.

