A lexical scope in JavaScript means that a variable defined outside a function can be accessible inside another function defined after the variable declaration. But the opposite is not true; the variables defined inside a function will not be accessible outside that function.
var x=15;
test();
function test()
{
var y=20;
console.log(x);
}
console.log(y);
No comments:
Post a Comment