If we declare a variable using there.
The declaration part will be hoisted to the scope.
Top if we console log the variable prior to its declaration we will not get any error messages.
We will get undefined which is the default Variable value.
If we declare a variable using let the declaration part will not be hoisted but a temporal dead zone
will be created between the letter statement and the scope top inside this zone.
The variable cannot be used.
Next we create a function and name it.
Test
then we invoke it online.
3 The test function is defined online for but invoked on line 3.
What kind of result will we get we can see the function has been invoked successfully.
This is because the declaration of a function will also be hoisted to the scope top.
But unlike the declaration of a variable the function name and the function body will be hoisted to
the scope together.
This is why we can invoke a function in front of its declaration.
Next we declare a global variable using the same name as the function
then at the top of the scope we console log test.
What kind of result will we get this time we can see we got the function body.
The conclusion is the hoisting of a function is higher than that of a variable.
Next behind the function and variable declaration we console log test again
we can see this time we got the variable value not the function body.
The conclusion is the declaration of a variable overrides that of a function.
If in the same scope we name a function and a variable the same at the end the name will represent the
variable not the function hoisting however works in the opposite way.
A function hoisting will override a variable hoisting
next.
Let's try a more complicated scenario.
We create a function outer we name its argument.
Test inside the outer function we declare a variable using there and name it.
Test then we create a child function and also name it test
we console log test at the top of the function scope
then at the end of the function scope we console log test again.
What kind of result will we get this time.
We invoke the outer function and set its argument value to hello
we can see the first console log gives us the child function.
The second one gives us the value of the test variable not the argument value we pass to the outer function.
This proves the argument has the lowest priority inside a function scope.
Actually the argument name is treated as a variable name in the function scope defining an argument
actually means declaring a variable inside the function scope.
We can prove this inside the outer function we declare test using let unlike there let does not allow
us to repeatedly declare the same variable if we run the program.
We will get an error message.
We can see the error is caused by line 13 where we declare test using let it told us the identifier
test has already been declared.
We will get the same error message.
If we repeatedly declare the same variable using let this proves the name test has already been declared
as a variable in the function scope.
The conclusion is defining an argument will create a variable under the argument name in the function
scope.