Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,750 --> 00:00:05,420
In the last section, we put together our cards with suit method and we made special use of the wear
2
00:00:05,430 --> 00:00:09,360
function that is included with every list automatically in the section.
3
00:00:09,360 --> 00:00:14,850
We're going to do a very small refactor to this function right here to make use of an abbreviated syntax
4
00:00:14,850 --> 00:00:16,530
for defining functions.
5
00:00:17,130 --> 00:00:22,110
So I want you to notice right now that when we call where we passed in a function that gets called one
6
00:00:22,110 --> 00:00:28,350
time for every element in the array, and we used what is referred to as the long form function syntax
7
00:00:28,350 --> 00:00:32,759
right here, the long form function syntax makes use of these curly braces.
8
00:00:34,110 --> 00:00:36,300
And we also had the return statement in there as well.
9
00:00:37,630 --> 00:00:43,990
Notice how the body of our function really just has one single expression inside of it in a single expression,
10
00:00:43,990 --> 00:00:46,750
just looks at one property and compares it to another.
11
00:00:46,960 --> 00:00:49,150
So this is one single expression.
12
00:00:50,500 --> 00:00:56,080
Because we have one expression inside of here, we can use a slightly abbreviated syntax for defining
13
00:00:56,080 --> 00:01:00,550
this function, so we're going to do the refactor and we'll talk about the differences between the two.
14
00:01:01,370 --> 00:01:05,140
So I'm going to first get started on this refactor by removing the semicolon.
15
00:01:06,260 --> 00:01:10,670
I'll then remove the return statement and I'll put all this stuff on one line.
16
00:01:12,040 --> 00:01:12,640
Like so.
17
00:01:13,640 --> 00:01:18,890
I'll then remove this curly brace on the right hand side, and then I will replace the curly brace on
18
00:01:18,890 --> 00:01:22,940
the left hand side with an equal sign and a greater than sign like.
19
00:01:22,940 --> 00:01:25,790
So oops did not mean to click that.
20
00:01:25,820 --> 00:01:26,210
There we go.
21
00:01:27,460 --> 00:01:32,410
So what we have on the screen right here is completely equivalent to what we had before, so because
22
00:01:32,410 --> 00:01:37,240
we had one single expression, we can make use of this arrow function syntax.
23
00:01:37,750 --> 00:01:43,480
If we had multiple expressions or multiple lines of code, we could not use the abbreviated syntax.
24
00:01:44,230 --> 00:01:48,730
The other thing I want to make clear is that when we use this arrow, we get what's called an implicit
25
00:01:48,730 --> 00:01:49,270
return.
26
00:01:49,930 --> 00:01:54,790
So whatever this expression right here evaluates to will be automatically returned from the function
27
00:01:54,790 --> 00:02:02,830
before us when we had the long form syntax with the curly braces like so we had to manually put in a
28
00:02:02,830 --> 00:02:03,820
return statement.
29
00:02:04,270 --> 00:02:10,389
So because we had a single expression and we made use of the Arrow syntax, we got an automatic return
30
00:02:10,389 --> 00:02:10,960
for free.
31
00:02:12,060 --> 00:02:17,070
So if I now run this code again, you'll notice that I get the same result up here on the top, right,
32
00:02:17,070 --> 00:02:18,240
just like I did before.
33
00:02:19,600 --> 00:02:23,620
We're going to be making use of this abbreviated syntax quite a bit throughout this course and will
34
00:02:23,620 --> 00:02:29,410
sometimes also swap off back to that longer form syntax any time we need to have multiple expressions
35
00:02:29,410 --> 00:02:30,760
inside of our function body.
36
00:02:31,300 --> 00:02:33,940
So we're going to see the syntax quite a bit both ways.
37
00:02:34,570 --> 00:02:34,890
All right.
38
00:02:34,900 --> 00:02:36,540
So we've got a good reflector here.
39
00:02:36,580 --> 00:02:38,260
Let's continue in the next section.
3954
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.