Originally Posted by BaronZ
i understand the example u showed me.but in the code i showed above,i think 'a' is a local variable,so in my opinion,alert(a) should pop up 'undefined' or sth,but it's '2',that's what confused me.
If your code fragment is not contained within a function then the variable a is global scope. Do what I say - study the topic.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.