Possible Duplicate:
is there any Advantage of redeclaring javascript variables?
Why does the following code display 1 rather than undefined:
a = 1;
var a;
alert(a);
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.
1)
vardoes not redeclare or delete a variable2) even if it did, your code gets rewritten* using javascript hoisting rules (any variable or function declaration gets moved to the top of the nearest enclosing function) as follows:
(*effectively rewritten; see RobG’s comments and links on entering of execution contexts for clarification)