1
00:00:00,200 --> 00:00:01,130
Hello, guys.

2
00:00:01,130 --> 00:00:02,810
Good to see you back once again.

3
00:00:02,820 --> 00:00:08,360
I'm back with a new tutorial related advanced JavaScript and in this tutorial we are going to learn

4
00:00:08,360 --> 00:00:10,310
what is modules.

5
00:00:10,310 --> 00:00:14,480
Let's try to understand modules with graphical pictures.

6
00:00:14,480 --> 00:00:20,750
Suppose we have two JavaScript file file one dot js and file two dot js.

7
00:00:20,750 --> 00:00:25,670
And in file one dot js we declare some variable, create some functions.

8
00:00:25,670 --> 00:00:33,380
Also, we create some classes and now I want to use this variable function and classes in file two.

9
00:00:33,410 --> 00:00:38,240
It is not mandatory that I am going to use all of these variables, function and classes.

10
00:00:38,240 --> 00:00:44,750
I want to run any particular function, otherwise I want to call any particular variable for that JavaScript.

11
00:00:44,750 --> 00:00:47,750
Introduce modules using modules.

12
00:00:47,750 --> 00:00:51,890
We can use JavaScript function variable classes in other files.

13
00:00:51,890 --> 00:00:56,900
It's increase our code reusability and it is very easy to maintain.

14
00:00:56,900 --> 00:01:01,430
Also it reduce HTML page loading in our file one dot js.

15
00:01:01,430 --> 00:01:06,050
We have lot of functions, but I want to decide I want to use only one function.

16
00:01:06,050 --> 00:01:09,650
Then I'm going to include this function in our file too.

17
00:01:09,680 --> 00:01:13,850
Then we can link this file to with our HTML document.

18
00:01:13,880 --> 00:01:19,130
That's why our HTML file become so fast in JavaScript module.

19
00:01:19,130 --> 00:01:20,930
It's come with two functions.

20
00:01:20,930 --> 00:01:25,400
First one is export function and second one is import function.

21
00:01:25,400 --> 00:01:28,910
So let's see how we can use these two function in our code.

22
00:01:29,450 --> 00:01:35,990
As I told you, we have to tell two file file one dot js and file two dot js in file one.

23
00:01:36,020 --> 00:01:41,960
Here I declare a variable name, a function hello and a class which is user.

24
00:01:42,320 --> 00:01:46,280
And now I decide I want to use name variable in file two.

25
00:01:46,280 --> 00:01:50,000
I don't want to use hello function and user class.

26
00:01:50,330 --> 00:01:56,840
For that we need to use a keyword and the keyword is export this export keyword.

27
00:01:56,840 --> 00:02:01,220
Give this variable a permission that we can use it in other files.

28
00:02:01,220 --> 00:02:07,970
And whenever we need to use this variable in file two, then we need to write a special statement,

29
00:02:07,970 --> 00:02:09,290
something like that.

30
00:02:09,290 --> 00:02:14,630
At first we need to type import keyword and then we need to use curly braces.

31
00:02:14,660 --> 00:02:20,450
Then inside the curly braces we need to pass the variable name which variable I want to import from

32
00:02:20,450 --> 00:02:21,890
file one dot js file.

33
00:02:21,890 --> 00:02:28,790
Then we need to type from and after that we need to pass the file location from which file I want to

34
00:02:28,790 --> 00:02:30,320
import this variable.

35
00:02:30,440 --> 00:02:33,770
And if you notice you can see before file one dot js.

36
00:02:33,800 --> 00:02:35,840
Here I use some special characters.

37
00:02:35,870 --> 00:02:37,610
Dot backslash.

38
00:02:37,610 --> 00:02:41,510
Whenever we use modules we need to provide our file path like that.

39
00:02:41,510 --> 00:02:43,100
And you need to remember this.

40
00:02:43,100 --> 00:02:46,790
And now I decide I want to use the name variable in file two.

41
00:02:46,820 --> 00:02:51,110
We can use this variable as like other variables we can print it in our console.

42
00:02:51,110 --> 00:02:52,730
Also we can print it in our document.

43
00:02:52,730 --> 00:02:58,070
With that we can perform calculations at the same way if we want to export this function.

44
00:02:58,070 --> 00:02:58,460
Yes.

45
00:02:58,460 --> 00:03:01,610
Just we need to type export keyword before the function name.

46
00:03:01,610 --> 00:03:05,270
Then we can use this function in file two dot js file.

47
00:03:05,270 --> 00:03:09,410
Here just we need to import the function import inside the curly braces.

48
00:03:09,590 --> 00:03:11,990
Just we need to pass the function name.

49
00:03:11,990 --> 00:03:13,250
Not any parentheses.

50
00:03:13,250 --> 00:03:16,250
Otherwise curly braces just function name.

51
00:03:16,250 --> 00:03:19,400
Then we can use this function like other functions.

52
00:03:19,400 --> 00:03:26,150
At the same way you can export this class and you need to follow the same procedure to import this class

53
00:03:26,150 --> 00:03:28,130
from the file one dot js.

54
00:03:28,160 --> 00:03:30,860
Then we can create objects using this class.

55
00:03:30,860 --> 00:03:36,800
And if you want to import variable, function and class at once, yes, you can just after import inside

56
00:03:36,800 --> 00:03:39,170
the curly braces you need to pass the variable name.

57
00:03:39,170 --> 00:03:40,400
Then you need to use comma.

58
00:03:40,580 --> 00:03:43,430
Then you need to pass the function and class name.

59
00:03:43,430 --> 00:03:46,910
Then you don't need to type multiple import keyword.

60
00:03:46,910 --> 00:03:51,080
And now you want to import this JS file in your HTML documents.

61
00:03:51,080 --> 00:03:54,200
For that just you need to do something.

62
00:03:54,200 --> 00:03:59,570
But inside the script tag you need to provide the type type module.

63
00:03:59,720 --> 00:04:03,050
Just you need to declare that this is a module file.

64
00:04:03,050 --> 00:04:08,600
Then as source you need to follow the relative path dot backslash.

65
00:04:08,600 --> 00:04:11,360
So this is the introduction tutorial of module.

66
00:04:11,360 --> 00:04:14,210
In the next tutorial we are going to start the practical.

67
00:04:14,210 --> 00:04:15,920
So thanks for watching this video.

68
00:04:15,920 --> 00:04:17,780
Stay tuned for the next tutorial.
