Transcript
00:00 Okay. Let's just build out what this has for us. So we're making a a logging system. So I'm gonna make a function called log info that, simply logs, but we're gonna have this prefix of info. And that that's what makes it a logging system.
00:15 Right? And we're gonna make a log error and that's got a prefix of error. There's actually a console dot error that you can call. There's also a warn and an info and a dir and I feel like there are a couple others. But, and and oh, yeah.
00:29 Group and time and, you know, there's a whole bunch of stuff you can do with console. But we're just gonna stick with log, here, for now. And then we've got, log with time stamps. So we're gonna create a time stamp and log that. K.
00:42 That's cool. And then we'll log all those and we'll export them. Alright. Great. So we've got our info, we've got our error, we've got our time stamp.
00:50 Everything is good. What does this have to do with void? Well, you'll notice the AI actually kinda did this for us and and Marty the money bag was here telling you to do this as well. But explicitly typed each one of these as void. What that does is it means that I cannot return anything.
01:04 I can't I can't return anything, except for undefined because undefined is technically the same thing that you would get if we return nothing, if you don't have a return statement. So, we're getting, a void return here. Now what's kinda interesting is here we have our type is defined as returning void. If I remove that, then our type is actually technically defined as returning undefined. So you can see how these concepts kind of overlap a little bit, but we don't actually need to return undefined.
01:35 And without that, it's going to say that we returned void, which effectively, all that really does is it means that I can't do anything to this. Like, it it returned nothing. There's nothing that I can call, on here. I cannot assign it to a value and have that value, have anything on it. There's there's just nothing that I can do with it.
01:56 That value is void. It's it's just nothing. That's why I say we're talking about nothing because void explicitly, by typing it explicitly or just not returning anything from your your function, you're saying just nothing for this. Void is actually not just a TypeScript thing either. Void is a feature of JavaScript.
02:16 So you can actually say, const x equals void zero. That is a this is a fun little, trivia here. Even today, we still have bundlers and JavaScript minifiers that try to take the code that you write and make it as small as possible. Use as few characters as possible because it will load faster for whoever is downloading your website. And so, we can have this, const y equals undefined or we can have, const equals void one of these and we can, like, eliminate all the characters that we possibly can and everything.
02:55 One of these is shorter than the other. And so actually, a minifier is going to go through your code and it's gonna find everywhere it finds undefined and it's going to change it for void zero, because that is faster. You can it's not just zero. You can have it be a string, but by adding void to it, it just makes this expression undefined regardless of what what it returns. You could say, date dot now which returns the time stamp for the current date.
03:21 And with without the void, you're gonna get number. But if you add a void, it turns that into undefined. Like I said, this isn't something you do a whole lot. Pretty much the only time I ever do this is when I, do some sort of asynchronous thing. I call a function that returns what's called a promise and I want to ignore that promise.
03:42 Typically, you would put an await there to wait for that promise to finish and and everything. Now, if I want to ignore that result, I just put void to say, no, I didn't forget the await keyword. I literally don't care what this promise returns or or when it results or anything. That is something we're gonna talk about way later. So if that kinda went over your head, don't worry about it.
04:01 You typically don't use void and you typically don't even explicitly type your functions as returning void. You just don't return anything and then they're void. So if you see something that says void, now hopefully you understand void just means nothing into the void. Alright. Great job on that one.
04:18 We'll see you in the next
