1
00:00:00,810 --> 00:00:03,270
If we declare a variable using there.

2
00:00:03,370 --> 00:00:05,910
The declaration part will be hoisted to the scope.

3
00:00:05,910 --> 00:00:12,640
Top if we console log the variable prior to its declaration we will not get any error messages.

4
00:00:13,680 --> 00:00:17,400
We will get undefined which is the default Variable value.

5
00:00:17,760 --> 00:00:24,060
If we declare a variable using let the declaration part will not be hoisted but a temporal dead zone

6
00:00:24,060 --> 00:00:29,040
will be created between the letter statement and the scope top inside this zone.

7
00:00:29,040 --> 00:00:31,160
The variable cannot be used.

8
00:00:31,170 --> 00:00:33,300
Next we create a function and name it.

9
00:00:33,300 --> 00:00:33,810
Test

10
00:00:39,050 --> 00:00:40,310
then we invoke it online.

11
00:00:40,310 --> 00:00:46,760
3 The test function is defined online for but invoked on line 3.

12
00:00:46,770 --> 00:00:53,880
What kind of result will we get we can see the function has been invoked successfully.

13
00:00:53,880 --> 00:00:58,930
This is because the declaration of a function will also be hoisted to the scope top.

14
00:00:59,070 --> 00:01:04,650
But unlike the declaration of a variable the function name and the function body will be hoisted to

15
00:01:04,650 --> 00:01:06,150
the scope together.

16
00:01:06,150 --> 00:01:10,290
This is why we can invoke a function in front of its declaration.

17
00:01:10,290 --> 00:01:14,550
Next we declare a global variable using the same name as the function

18
00:01:18,400 --> 00:01:21,790
then at the top of the scope we console log test.

19
00:01:21,790 --> 00:01:28,060
What kind of result will we get this time we can see we got the function body.

20
00:01:28,060 --> 00:01:32,800
The conclusion is the hoisting of a function is higher than that of a variable.

21
00:01:32,980 --> 00:01:37,960
Next behind the function and variable declaration we console log test again

22
00:01:42,280 --> 00:01:46,690
we can see this time we got the variable value not the function body.

23
00:01:46,720 --> 00:01:51,610
The conclusion is the declaration of a variable overrides that of a function.

24
00:01:51,610 --> 00:01:57,610
If in the same scope we name a function and a variable the same at the end the name will represent the

25
00:01:57,610 --> 00:02:02,380
variable not the function hoisting however works in the opposite way.

26
00:02:02,530 --> 00:02:05,890
A function hoisting will override a variable hoisting

27
00:02:10,360 --> 00:02:10,800
next.

28
00:02:10,810 --> 00:02:13,340
Let's try a more complicated scenario.

29
00:02:13,480 --> 00:02:17,390
We create a function outer we name its argument.

30
00:02:17,530 --> 00:02:25,190
Test inside the outer function we declare a variable using there and name it.

31
00:02:25,190 --> 00:02:31,350
Test then we create a child function and also name it test

32
00:02:34,840 --> 00:02:37,780
we console log test at the top of the function scope

33
00:02:41,620 --> 00:02:45,880
then at the end of the function scope we console log test again.

34
00:02:45,880 --> 00:02:48,360
What kind of result will we get this time.

35
00:02:48,400 --> 00:02:52,510
We invoke the outer function and set its argument value to hello

36
00:02:55,970 --> 00:02:59,690
we can see the first console log gives us the child function.

37
00:02:59,690 --> 00:03:06,130
The second one gives us the value of the test variable not the argument value we pass to the outer function.

38
00:03:06,140 --> 00:03:10,840
This proves the argument has the lowest priority inside a function scope.

39
00:03:10,880 --> 00:03:16,760
Actually the argument name is treated as a variable name in the function scope defining an argument

40
00:03:16,850 --> 00:03:21,020
actually means declaring a variable inside the function scope.

41
00:03:21,020 --> 00:03:28,370
We can prove this inside the outer function we declare test using let unlike there let does not allow

42
00:03:28,370 --> 00:03:32,380
us to repeatedly declare the same variable if we run the program.

43
00:03:32,390 --> 00:03:34,360
We will get an error message.

44
00:03:34,430 --> 00:03:40,850
We can see the error is caused by line 13 where we declare test using let it told us the identifier

45
00:03:40,850 --> 00:03:42,690
test has already been declared.

46
00:03:42,890 --> 00:03:44,750
We will get the same error message.

47
00:03:44,780 --> 00:03:50,810
If we repeatedly declare the same variable using let this proves the name test has already been declared

48
00:03:50,810 --> 00:03:53,100
as a variable in the function scope.

49
00:03:53,240 --> 00:03:59,000
The conclusion is defining an argument will create a variable under the argument name in the function

50
00:03:59,000 --> 00:03:59,390
scope.

