var a = 1;
function b() {
a = 10;
return;
function a() {}
}
b();
alert(a);
How is the output of 1 displayed for a? What does the
return;
function a() {}
within the function body perform?
You declare a symbol "a" in the function with its last line. That's the "a" affected by the assignment statement.
Function declaration statements are hoisted up to the top of the function and are interpreted first. Thus, the assignment statement effectively happens after you've declared a function (local to the "b" function) named "a". The assignment, therefore affects that symbol, not the global "a".
Remember that variables aren't typed, so the fact that you've bound a name to a function doesn't prevent it from being assigned a numeric value later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With