1
00:00:01,050 --> 00:00:05,190
In this video, there's one last quick thing I want to mention, and that is one very special type that

2
00:00:05,190 --> 00:00:07,920
we haven't really discussed too much except in kind of passing.

3
00:00:08,610 --> 00:00:11,070
So at the bottom of this file, I want you to find one more function.

4
00:00:11,490 --> 00:00:13,500
I'm going to define a function called logger.

5
00:00:14,070 --> 00:00:16,079
This thing is going to take some message.

6
00:00:16,079 --> 00:00:17,190
That is a string.

7
00:00:18,070 --> 00:00:22,000
And then inside the function, I want you to just console log that message like so.

8
00:00:23,100 --> 00:00:28,230
So the only goal of this function is to call console log, and it does not actually return any value.

9
00:00:28,650 --> 00:00:33,750
So there's no return statement inside of here to annotate this fact as a return type.

10
00:00:33,780 --> 00:00:35,880
We'll put on Colen void like.

11
00:00:35,880 --> 00:00:40,890
So it's a void right here means that we have a function that's going to not return anything.

12
00:00:41,520 --> 00:00:44,910
Technically, a function that returns void can return null.

13
00:00:46,150 --> 00:00:53,110
And it can also return undefined, but effectively we use void right here to say there will be no return

14
00:00:53,110 --> 00:00:57,310
value from this function if we ever accidentally return something like so.

15
00:00:57,530 --> 00:01:00,970
Well, very quickly get an error message that says, hey, you can't return anything at all.

16
00:01:02,040 --> 00:01:06,070
Now, there's one other very special type associated with function return values as well.

17
00:01:06,510 --> 00:01:12,570
So I'm going to make one more function in here called throw error and throw ER will also take a message

18
00:01:12,570 --> 00:01:13,410
that is a string.

19
00:01:14,340 --> 00:01:20,460
And then any time we call this, I'm going to immediately throw a new air with that message like so.

20
00:01:21,760 --> 00:01:26,620
And just, you know, any time you throw an error, the function will technically not actually return

21
00:01:26,620 --> 00:01:27,250
anything.

22
00:01:28,370 --> 00:01:33,140
So to indicate that we could put on a Colen right here that says never, and that means that we are

23
00:01:33,140 --> 00:01:35,960
never going to actually reach the end of this function.

24
00:01:36,170 --> 00:01:40,340
So we're never going to execute the function completely at some point in time inside of here, we're

25
00:01:40,340 --> 00:01:44,360
going to throw an error and exit the function early without returning any value.

26
00:01:45,380 --> 00:01:49,460
Now, this is a really big court case, it's actually pretty darn rare that we're going to want to,

27
00:01:49,460 --> 00:01:55,460
like, intentionally throw in air like this, it's much more common for us to have some, like, actual

28
00:01:55,460 --> 00:02:00,650
return value in here, like, let's say if there is no message for some reason.

29
00:02:02,160 --> 00:02:03,390
Then we will throw in air.

30
00:02:04,560 --> 00:02:10,139
And then otherwise, we'll return like a. maybe just a message like so and so in this case, we would

31
00:02:10,139 --> 00:02:13,320
still imitate this as returning a string, even though it throws an error.

32
00:02:13,830 --> 00:02:20,040
So we only annotate a function with the type never when we really, truly never expect a function to

33
00:02:20,040 --> 00:02:21,750
return anything ever.

34
00:02:22,380 --> 00:02:26,880
If we at least expect it to return something eventually and only possibly through an error, that's

35
00:02:26,880 --> 00:02:27,480
totally fine.

36
00:02:27,480 --> 00:02:30,660
We're still going to annotate it with whatever we expect it to eventually return.

37
00:02:31,380 --> 00:02:33,450
And that does include the case where we return.

38
00:02:33,450 --> 00:02:34,160
Nothing like so.

39
00:02:34,170 --> 00:02:39,210
So in this case, we would still do a fallback to void because we are technically not returning anything

40
00:02:39,330 --> 00:02:42,870
and there's just a chance of us never reaching the end of the function.

41
00:02:44,130 --> 00:02:45,540
OK, so that's pretty much it.

42
00:02:45,750 --> 00:02:48,570
Let's take a quick pause right here and move on to our next subject.

