Curious bit of code here…
var x = 5;
function fn() {
x = 10;
return;
function x() {}
}
fn();
alert(x);
Here’s the jsFiddle
Is function x() {} called at all after return ?
Why not alert 10?
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.
function x() {}is hoisted to the start offn‘s scope, and this effectively makesxa local variable beforex = 10;is evaluated.The function is not set to10.Update: The sentence above is wrong.
xis actually set to10.varis not used to declare it, but even if it was, the last sentence in the quote below only refers to the declaration part of the namex, not its assignment to10.From MDN (emphasis mine):