Hello, guys.
Good to see you back.
This is the another part of this module tutorial.
And today in this tutorial we are going to learn default function module came with a default function.
So let's see how we can create this function.
Also we are going to see how we can use it.
So let's back to the library dot js file.
First I'm going to comment out all of this code.
And then I'm going to create default function.
To create default function we need to use default keyword default default function, then parenthesis.
Then inside the round braces.
This default function basically represents the whole file with that.
Also I want to export this function.
So here I'm going to type export keyword.
Export.
And here I'm going to type something.
So type console dot log inside the round braces inside the double quotes.
Hello and semicolon too in this line.
Now let's back to the main dot js file.
Also I'm going to comment out all of this code and I'm going to duplicate this line and comment out
previous one.
And to import default function, you need to use the same process.
Let me show you how.
So I'm going to remove this star sign.
And as and inside the curly braces I'm going to pass the function name which is default.
Default.
Also you need to take alias name as de.
That's it.
And now we can call this function.
So here I'm going to type D and semicolon two in this line after save this file.
As you can see in my browser it's written hello.
We don't need to take any name for this function whenever we call this function.
Otherwise import this function.
We take this name for this function.
Now, at last I am going to introduce you another feature of module.
Which is known as aggregate module.
Here we are going to learn how we can use multiple module in a file.
So at first I'm going to comment out this line.
Then I'm going to uncomment this import line.
With that let's back to the language's file.
And from library dot js file.
First I'm going to comment out this line.
I don't need this line for now.
And also I'm going to uncomment this export line.
I want to export only user function nothing else.
With that we need to uncomment this user function.
That's it.
Also I'm not going to pass any argument.
So I remove this arguments.
And here I'm going to type simply a text hello world.
And I'm going to save this file.
So in this library function we have only one function named user.
And if you notice you can see we have another file mediator dot js.
So let's jump into this file.
This file going to play the role of a bridge between these two file main.js and library JS.
And for your better understand I'm going to move this file between this library and main JS in our library
dot js file.
Here we export user function.
And here I use the main js file.
And in our HTML file we include the main dot js file.
But in Maine dot js file.
Here I'm going to change the import file path this time.
So I'm going to duplicate this line and comment out previous one.
This time I want to import mediator dot js.
So here I'm going to type mediator dot js file.
And I want to import the particular user function.
So here I'm going to remove the name and start sign.
And inside the curly braces I'm going to type user.
Now the question is we do not create user function in mediator dot js file.
So in the mediator dot js file I'm going to import the function from library dot js file.
So I'm going to type import inside the round.
Inside the curly braces.
Our function name user from library dot js file.
Library dot js.
And I'm going to save this file.
So in our mediator file we import the user function from live dot js.
Then in our main dot js file we import the user function from mediator dot js file.
But if I save this files it's going to return an error something like that.
It is a syntax error.
Here it print media.
JS does not provide an export named user to resolve this problem.
If we want to use any breeze file for that here we need to use export keyword.
So I duplicate this line and comment out previous one.
And here we need to type export.
Now if I save this file now you can see there is no error in my console.
So in our main dot js file if I call user function and remove the argument because this time I do not
handle any argument in our user function and save this file.
You can see the result.
Now it's print hello world!
So at first we export from library to mediator.
Then from the mediator we export Main.js file.
So this is it for this tutorial.
In the next tutorial we are going to learn about promises.
So thanks for watching this video.
Stay tuned for the next tutorial.