var x = 5;
function test2(x) {
  x = 7;
}
test2(8);
alert(x);Why exactly is this putting out the global var x=5, without being affected by anything within the function.
var x = 5;
function test2(x) {
  x = 7;
}
test2(8);
alert(x);Why exactly is this putting out the global var x=5, without being affected by anything within the function.
 
    
     
    
    Because you passed a param called x, which is the same name as your global var. Try this out:
var x = 5;
function test2(y) {
  x = y;
}
test2(8);
alert(x);