i have a global variable x, which has the same name as that of the inner function when i execute the test function it also executes the function which has same as that of the global variable, this function contains assigns value to the variable which has the same name as that of the function, now when in the next line it alerts the value of the x, it alerts 2, but when after the execution of the test function if you alert the x it still alerts 10... y?
eg
var x =10; //assigns value 10 to global variable x
function test(){
function x () {
x = 2; //assigns value x
alert(x); // x =2
}
x(); //calls x
}
test(); //call function test
but if you alert x, then it gives 10... why like this;
and if you do like this
var y =10; //assign value 10 to y
function test(){
function x () {
y = 2; //assign value 2 to y
alert(y); //alerts y is 2
}
x(); //call the function x
}
test(); //call the test function
and if you check y then also it is 2.. what is the difference between the two.. I know the behaviour of the second one.. but have no idea about the first one...