JS Coding Questions Logo
JS Coding Questions
#467💼 Interview💻 Code

What is Lexical Scope?

Advertisement

728x90

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

js
1<script>
2  function x(){
3  var a=10;
4  function y(){
5  console.log(a); // will print a , because of lexical scope, it will first look 'a' in
6  //its local memory space and then in its parent functions memory space
7  }
8  y();
9  }
10  x();
11  </script>

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 39

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
467of476