Transcript
00:00 Okay. Let's do some export. So we've got this utils module right here, and, we're importing some things from the utils module. We've got this bomb here that's saying, hey. We wanna remove this comment.
00:12 And the reason we, had the comment in there in the first place is because without it, this is blowing up. And so we've gotta fix that. Let's go ahead and, remove the or add these logs, and we'll add this export while we're here. And let's now jump into utils, and we wanna export. So you'll notice we've got format currency, format date.
00:31 So I'm gonna add an export to this and wanna add an export to that. And, yeah, then we're going to add a special kind of export for this one. This is gonna be export default class formatter, and that's going to handle, format currency and format date. And that makes everything happy. Well, what is the difference here?
00:51 So we've got this default thing. The, benefit of default here is that while with named, imports, you don't have to, or you have to use the name that they exported it as. Here I can even auto complete to that. If you wanted to use a different name, you have to alias it, which is maybe kind of annoying, to have to do that. With a default export, you can call it whatever you want and, it will import the default export, whatever it's called.
01:23 There are goods and bads to that. One thing I don't like about that is then the name of that thing that's exported was gonna be different all over where it's, being imported. I'm not a super huge fan of that. That's that's honestly that's like the biggest reason. And also, like, knowing what the default export is can be kind of hard.
01:46 If I'm saying, okay. I wanna import the default, from that. Is that make formatter? Or is it a formatter, class? I I just I don't know I don't know what to call it, and I don't know how to treat it.
01:58 So I'm gonna have to go in here to understand what it is, or, I can say format or class, and then I can look at this and see if they have JS doc or something like that. I don't like that. The nice thing about this is that it does tell you what is available. Here's all the things that are available, and you can, oh, format date. Okay.
02:14 I know how to use that format currency. Yeah. That makes sense. So the I pretty much never use defaults. However, there are some frameworks that have a convention that you export a default value from your module.
02:29 For those frameworks, like, you don't really get a choice. You just have to do a default export. But in those cases, you're not the one importing that default. It's the framework that's gonna import the default for you. So it's fine.
02:38 It's fine. Alright. I think that's everything I wanted to say about that. Let me just make sure. Oh, yes.
02:46 Also, you can do this in one line, and I typically do. So you can say formatter and then comma, and then you can do your name space to export. So here's your default import, and then here's the default or the name space or the named imports. And so you can do all that altogether. I actually I I hadn't thought about this, but, yeah.
03:06 You can't do it in the reverse order. So default always comes first. I've actually never tried that until just now, so there you go. Named comes second. And then on top of that, if you do star as utils, then you've got utils dot, and, the utils for the default is actually gonna be default.
03:26 So there you go. Another reason to not like default exports. Alright. Hopefully that was fun and interesting to you. Good job on this one.
