Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,009 --> 00:00:03,870
Now what you see here is one way
2
00:00:03,870 --> 00:00:05,939
of defining a function
3
00:00:05,939 --> 00:00:08,730
but I'm going to comment out this approach here
4
00:00:08,730 --> 00:00:12,960
for the moment because there also is an alternative.
5
00:00:12,960 --> 00:00:13,830
In JavaScript,
6
00:00:13,830 --> 00:00:16,440
you can also create so-called arrow functions,
7
00:00:16,440 --> 00:00:18,390
a syntax that's especially popular
8
00:00:18,390 --> 00:00:20,910
if you're dealing with anonymous functions,
9
00:00:20,910 --> 00:00:23,070
a function that don't need a name.
10
00:00:23,070 --> 00:00:25,500
For example, here in this React app I showed you
11
00:00:25,500 --> 00:00:29,100
in the first course section, you might remember
12
00:00:29,100 --> 00:00:32,729
that on the buttons we had this on click attribute
13
00:00:32,729 --> 00:00:36,810
and we used some React syntax to point at a function
14
00:00:36,810 --> 00:00:39,870
that should be executed when the button is clicked.
15
00:00:39,870 --> 00:00:43,170
And for that here I used this arrow function syntax
16
00:00:43,170 --> 00:00:47,250
to define a function in the place where it's needed
17
00:00:47,250 --> 00:00:50,010
as a value for this click listener.
18
00:00:50,010 --> 00:00:52,380
And this is a so-called anonymous function
19
00:00:52,380 --> 00:00:54,450
because it doesn't carry any name.
20
00:00:54,450 --> 00:00:56,463
It's just the function code.
21
00:00:57,360 --> 00:01:00,330
Now, anonymous functions can also be defined
22
00:01:00,330 --> 00:01:02,310
with the function keyword.
23
00:01:02,310 --> 00:01:04,569
You can define functions like this
24
00:01:05,670 --> 00:01:08,553
and for example, console log Hello.
25
00:01:09,450 --> 00:01:12,570
And we could then, for example, export this as a default
26
00:01:12,570 --> 00:01:15,060
if we wanted to, and we would now be exporting
27
00:01:15,060 --> 00:01:19,023
a so-called anonymous function which doesn't carry any name.
28
00:01:20,340 --> 00:01:23,670
But if you are dealing with such anonymous functions
29
00:01:23,670 --> 00:01:26,070
you can use the arrow function syntax as well
30
00:01:26,070 --> 00:01:28,050
since this is a bit shorter.
31
00:01:28,050 --> 00:01:29,670
When using arrow functions,
32
00:01:29,670 --> 00:01:33,870
you omit the function keyword, you must not use it
33
00:01:33,870 --> 00:01:36,900
and you instead just have your parameter list here
34
00:01:36,900 --> 00:01:39,450
like for example, username and message.
35
00:01:39,450 --> 00:01:41,370
This doesn't change.
36
00:01:41,370 --> 00:01:42,660
Then you have this arrow
37
00:01:42,660 --> 00:01:44,460
and then you have the curly braces
38
00:01:44,460 --> 00:01:46,323
which contain the function body.
39
00:01:47,610 --> 00:01:50,670
You can also still use the return keyword here
40
00:01:50,670 --> 00:01:54,210
if you want to, and that's how you would define a function
41
00:01:54,210 --> 00:01:57,120
using this arrow function syntax.
42
00:01:57,120 --> 00:02:00,210
In this course, you'll see both kinds of functions
43
00:02:00,210 --> 00:02:01,740
using the function keyword
44
00:02:01,740 --> 00:02:04,470
and using this arrow function notation.
45
00:02:04,470 --> 00:02:07,620
Ultimately, it is up to you which approach you prefer
46
00:02:07,620 --> 00:02:09,363
but you should know about both.
3636
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.