Originally Posted by BaronZ
umm,but if a is not global,why the alert box shows '2'?
I think you need to better understand global and local scope. You seem to be unclear. Study the example I have given you.
var a = 10;
var a = 40;
alert (a); // within the function alerts '40', not the global value of '10'
alert (a); // outside the function alerts global value of '10'
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.
Last edited by Philip M; 10-05-2012 at 09:08 AM..