Javascript has a scope. The variable is in scope within the function in which it was declared, which also includes any functions that you can define inside this function.
function () {
var x;
function () {
x = 42;
y = 'foo';
}
}
var.
var, Javascript , , - . x = 42 x, var x .
, Javascript . y window.y , , .
, . , var.