1 00:00:01,160 --> 00:00:05,180 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,180 --> 00:00:09,980 we haven't really discussed too much except in kind of passing to the bottom of this file I want to 3 00:00:09,980 --> 00:00:11,630 define one more function. 4 00:00:11,630 --> 00:00:14,140 I'm going to define a function called logger. 5 00:00:14,150 --> 00:00:19,890 This thing is going to take some message that is a string and then inside the function I want to just 6 00:00:19,890 --> 00:00:26,290 console log that message like so so the only goal of this function is to call console log and it does 7 00:00:26,290 --> 00:00:28,510 not actually return any value. 8 00:00:28,690 --> 00:00:34,870 So there's no return statement inside of here to annotate this fact as a return type we'll put on colon 9 00:00:34,960 --> 00:00:41,230 void like so it's a void right here means that we have a function that's going to not return anything. 10 00:00:41,590 --> 00:00:50,030 Technically a function that returns void can return null and it can also return undefined but effectively 11 00:00:50,070 --> 00:00:55,860 we use void right here to say there will be no return value from this function if we ever accidentally 12 00:00:55,860 --> 00:01:00,690 return something like So we'll very quickly get an error message that says hey you can't return anything 13 00:01:00,690 --> 00:01:02,100 at all. 14 00:01:02,120 --> 00:01:06,560 Now there's one other very special type associate with function return values as well. 15 00:01:06,560 --> 00:01:12,530 So going to make one more function in here called throw Error and throw Error will also take a message 16 00:01:12,560 --> 00:01:19,950 that is a string and then anytime we call this I'm going to immediately throw a new air with that message 17 00:01:19,950 --> 00:01:26,620 like so and just you know any time you throw an error the function well technically not actually return 18 00:01:26,620 --> 00:01:32,280 anything so to indicate that we could put on a colon right here that says never. 19 00:01:32,280 --> 00:01:36,840 And that means that we are never going to actually reach the end of this function so we're never going 20 00:01:36,840 --> 00:01:38,760 to execute the function completely. 21 00:01:38,760 --> 00:01:43,200 At some point time inside of here we're going to throw an error and exit the function early without 22 00:01:43,200 --> 00:01:45,490 returning any value. 23 00:01:45,490 --> 00:01:47,290 Now this is a really big corner case. 24 00:01:47,290 --> 00:01:52,300 It's actually pretty darn rare that we're going to want to like intentionally throw in error like this. 25 00:01:52,330 --> 00:01:59,110 It's much more common for us to have some like actual return value in here like let's say if there is 26 00:01:59,110 --> 00:02:06,580 no message for some reason then we will throw an error and then otherwise we'll return like an hour 27 00:02:06,620 --> 00:02:08,370 maybe just the message like so. 28 00:02:08,740 --> 00:02:13,900 And so in this case we would still annotate this as returning a string even though it throws an error. 29 00:02:13,900 --> 00:02:20,530 So we only annotate a function with the type never when we really truly never expect a function to return 30 00:02:20,800 --> 00:02:22,380 anything ever. 31 00:02:22,450 --> 00:02:27,100 If we at least expect it to return something eventually and only possibly throw an error that's totally 32 00:02:27,100 --> 00:02:31,230 fine we're still going to annotate it with whatever we expect it to eventually return. 33 00:02:31,480 --> 00:02:34,180 And that does include the case where we return nothing like so. 34 00:02:34,180 --> 00:02:39,430 So in this case we would still do a fallback to void because we are technically not returning anything. 35 00:02:39,430 --> 00:02:44,500 And there's just a chance of us never reaching the end of the function okay. 36 00:02:44,520 --> 00:02:45,770 So that's pretty much it. 37 00:02:45,770 --> 00:02:48,560 Let's take a quick pause right here and move on to our next subject.