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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You code is misleading and in a style that makes people think execution order matters. The standard JavaScript engine these days will take that and reformat prior to running it to:
Now you can understand what is actually happening. “a” is declared again inside the function “b” so there is actually two “a” variables now. One is “window.a” and the other one is “b var a” but NOT “b.a” because its not accessible outside of the closure or function.
In other words, you get what you code for.
Please make your code readable and don’t confuse the point.