In this video there's one last quick thing I want to mention and that is one very special type that
we haven't really discussed too much except in kind of passing to the bottom of this file I want to
define one more function.
I'm going to define a function called logger.
This thing is going to take some message that is a string and then inside the function I want to just
console log that message like so so the only goal of this function is to call console log and it does
not actually return any value.
So there's no return statement inside of here to annotate this fact as a return type we'll put on colon
void like so it's a void right here means that we have a function that's going to not return anything.
Technically a function that returns void can return null and it can also return undefined but effectively
we use void right here to say there will be no return value from this function if we ever accidentally
return something like So we'll very quickly get an error message that says hey you can't return anything
at all.
Now there's one other very special type associate with function return values as well.
So going to make one more function in here called throw Error and throw Error will also take a message
that is a string and then anytime we call this I'm going to immediately throw a new air with that message
like so and just you know any time you throw an error the function well technically not actually return
anything so to indicate that we could put on a colon right here that says never.
And that means that we are never going to actually reach the end of this function so we're never going
to execute the function completely.
At some point time inside of here we're going to throw an error and exit the function early without
returning any value.
Now this is a really big corner case.
It's actually pretty darn rare that we're going to want to like intentionally throw in error like this.
It's much more common for us to have some like actual return value in here like let's say if there is
no message for some reason then we will throw an error and then otherwise we'll return like an hour
maybe just the message like so.
And so in this case we would still annotate this as returning a string even though it throws an error.
So we only annotate a function with the type never when we really truly never expect a function to return
anything ever.
If we at least expect it to return something eventually and only possibly throw an error that's totally
fine we're still going to annotate it with whatever we expect it to eventually return.
And that does include the case where we return nothing like so.
So in this case we would still do a fallback to void because we are technically not returning anything.
And there's just a chance of us never reaching the end of the function okay.
So that's pretty much it.
Let's take a quick pause right here and move on to our next subject.