1
00:00:00,624 --> 00:00:04,749
Here's our first example. We declare an

2
00:00:04,749 --> 00:00:07,053
anonymous function with no parameters, and

3
00:00:07,053 --> 00:00:09,624
whose body contains a single statement

4
00:00:09,624 --> 00:00:12,124
returning the string Hello World! This

5
00:00:12,124 --> 00:00:15,124
function is then assigned to variable

6
00:00:15,124 --> 00:00:17,624
greetings. Next, they invoke this function

7
00:00:17,624 --> 00:00:19,957
and collect the return value in the

8
00:00:19,957 --> 00:00:22,224
message variable. Finally, we output the

9
00:00:22,224 --> 00:00:25,053
value of message to the console. The

10
00:00:25,053 --> 00:00:28,068
output, as expected, is Hello World! Now

11
00:00:28,068 --> 00:00:31,180
let's write the same code using arrow

12
00:00:31,180 --> 00:00:33,291
functions. Our anonymous function has been

13
00:00:33,291 --> 00:00:36,024
replaced by opening and closing

14
00:00:36,024 --> 00:00:39,124
parentheses. This implies that there are

15
00:00:39,124 --> 00:00:41,767
no input parameters. This is followed by

16
00:00:41,767 --> 00:00:44,338
an equal sign, immediately followed by a

17
00:00:44,338 --> 00:00:46,957
greater than sign. Finally, we have a

18
00:00:46,957 --> 00:00:49,291
block containing the body of our arrow

19
00:00:49,291 --> 00:00:51,767
function inside the opening and closing

20
00:00:51,767 --> 00:00:54,053
curly braces. This block is identical to

21
00:00:54,053 --> 00:00:56,957
the block in our previous example. Just

22
00:00:56,957 --> 00:00:59,195
like before, we are assigning this arrow

23
00:00:59,195 --> 00:01:01,124
function to the greetings variable before

24
00:01:01,124 --> 00:01:04,424
printing it to the console. We can

25
00:01:04,424 --> 00:01:06,749
simplify it further. Since our function

26
00:01:06,749 --> 00:01:09,224
body only has one statement, we can omit

27
00:01:09,224 --> 00:01:11,291
the braces, as well as the return

28
00:01:11,291 --> 00:01:13,910
statement as shown here. The string Hello

29
00:01:13,910 --> 00:01:16,957
World! is implicitly returned and assigned

30
00:01:16,957 --> 00:01:20,910
to the greeting variable. Let's see an

31
00:01:20,910 --> 00:01:23,374
example with one parameter. This is the

32
00:01:23,374 --> 00:01:25,481
same example that we have already been

33
00:01:25,481 --> 00:01:28,824
working with in this course. Instead of an

34
00:01:28,824 --> 00:01:30,424
anonymous function, we define a greetings

35
00:01:30,424 --> 00:01:32,874
function that takes in one input parameter

36
00:01:32,874 --> 00:01:35,291
called name and returns a string with

37
00:01:35,291 --> 00:01:37,624
Hello prepended to the name parameter.

38
00:01:37,624 --> 00:01:41,124
This function is assigned to the greet

39
00:01:41,124 --> 00:01:44,124
variable. Finally, we invoke this greet

40
00:01:44,124 --> 00:01:46,957
function with argument John and assign the

41
00:01:46,957 --> 00:01:49,124
value returned to variable message before

42
00:01:49,124 --> 00:01:52,824
printing it to the console. Now, here's

43
00:01:52,824 --> 00:01:55,624
the arrow function where the empty

44
00:01:55,624 --> 00:01:57,624
parenthesis has been replaced with the

45
00:01:57,624 --> 00:02:00,124
input parameter name. Everything else is

46
00:02:00,124 --> 00:02:03,291
exactly the same. So what did we learn

47
00:02:03,291 --> 00:02:06,624
here? If we have only one input parameter,

48
00:02:06,624 --> 00:02:09,624
the parenthesis around it is optional.

49
00:02:09,624 --> 00:02:11,957
This makes our code even more concise, and

50
00:02:11,957 --> 00:02:14,053
you'll come across JavaScript code with

51
00:02:14,053 --> 00:02:18,000
arrow functions defined at this manner all the time in the real world.

