FrontendDeveloper.in

JavaScript question detail

What is Lexical Scope?

Lexical scope is the ability for a function scope to access variables from the parent scope.

<script>
function x(){
var a=10;
function y(){
console.log(a); // will print a , because of lexical scope, it will first look 'a' in
//its local memory space and then in its parent functions memory space
}
y();
}
x();
</script>
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399