This is a named function expression with the name test
. Inside, I assign 123
to a variable, also named test
. Then test
is logged. The function prints its body in the console, but not 123
. What is the reason for such behavior?
(function test() {
test = 123;
console.log( test );
}());
Where does my explanation of function execution fail?
- Start of function execution:
test
is a local variable that references the function itself - Local variable
test
is reassigned to number123
console.log(test)
shows the number123
.
var test;
as in the linked question. – Stoppagethe name of the function is a "var" to the function...
". In the same manner as arguments are declared? If that's the case, is the function name somehow protected then? You can change the value of arguments thought they are "pre-declared". – Forcible