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
.