If you define:
var y = 'I am defined outside foo definition';
It will be a global window variable (in case you are using js in a browser), which can be accessed 'globally' by calling:
window.y
If you use it inside a function, like:
function foo(x) {alert(y);}
It will still refer a global variable, because it is not shadowed by function parameters.
If you define a function as:
function foo(y) {alert(y);}
Then y is being shadowed by function parameter (which is btw an alias for arguments[0]). Which means that all references to variable y inside this function will refer the parameter variable, not the global one. So for example:
var y = 'I am defined outside foo definition';
function foo(y) { y = 'something';}
alert(y);
will display I am defined outside foo definition.
Edit:
If you have a function:
function bar(x) {
alert(x);
}
and you try to call it using bar() then function parameter parameter x shadows global variable x. JS engine will look for local variable x and it will not be found - which means you will get undefined message in your alert.